AbilityModal.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <div>
  3. <el-dialog v-model="dialogVisible" title="装置功能配置" width="70%" @close="handleClose" :close-on-click-modal="false">
  4. <el-button type="primary" plain @click="addAbility(0)"><el-icon>
  5. <Plus />
  6. </el-icon>添加新功能</el-button>
  7. <el-upload style="display: inline-block;margin: 0 10px;" v-model:file-list="fileList" class="upload-demo"
  8. :show-file-list="false" :http-request="upTemplate" multiple :limit="1">
  9. <el-button type="primary" plain :disabled="upState">Excel上传</el-button>
  10. </el-upload>
  11. <el-button type="success" plain @click="downloadFile">模板下载</el-button>
  12. <el-table :data="tableData" style="width: 100%;height: calc(100vh - 600px);">
  13. <el-table-column label="序号" width="100">
  14. <template #default="scope">
  15. <span>{{ scope.$index + 1 }}</span>
  16. </template>
  17. </el-table-column>
  18. <el-table-column prop="func_name" label="设计功能名称" width="220" />
  19. <el-table-column prop="fcda_name" label="端子设计名称" width="220" />
  20. <el-table-column prop="fcda_match_exp" label="端子匹配关键词" width="220" />
  21. <el-table-column fixed="right" label="操作" width="auto">
  22. <template #default="scope">
  23. <el-button link type="primary" size="small" @click="addAbility(1, scope.row)">编辑</el-button>
  24. <!-- <el-popconfirm title="确认删除吗?" @confirm="firmSure">
  25. <template #reference> -->
  26. <el-button link type="primary" size="small" style="color: red;"
  27. @click="delAbility(scope.row)">删除</el-button>
  28. <!-- </template>
  29. </el-popconfirm> -->
  30. </template>
  31. </el-table-column>
  32. </el-table>
  33. <template #footer>
  34. <span class="dialog-footer">
  35. <el-button @click="cancels">取消</el-button>
  36. <el-button type="primary" @click="sureClick">确定</el-button>
  37. </span>
  38. </template>
  39. </el-dialog>
  40. <AddAbility v-if="addModal" :addModal="addModal" :modelIds="modelIds" :iedTypes="iedTypes" :copyReload="copyReload"
  41. :editOrAdd="editOrAdd" :editRow="editRow" @addAback="addAback" :tableData="tableData"></AddAbility>
  42. <DelAbility v-if="delModal" :delModal="delModal" :modelIds="modelIds" :delFcda="delFcda" :copyReload="copyReload"
  43. @delBack="delBack"></DelAbility>
  44. </div>
  45. </template>
  46. <script>
  47. import { ref, onMounted, watch, toRefs } from 'vue';
  48. import flow from "@/api/flow/flow"
  49. import system from '@/api/system';
  50. import AddAbility from './AddAbility.vue';
  51. import DelAbility from './DelAbility.vue';
  52. import { ElMessage } from 'element-plus';
  53. export default {
  54. props: {
  55. abModal: {
  56. type: Boolean,
  57. required: true
  58. },
  59. modelId: {
  60. type: String,
  61. required: true,
  62. },
  63. iedType: {
  64. type: String,
  65. required: true,
  66. }
  67. },
  68. setup(props, { emit }) {
  69. let dialogVisible = ref(false)//模态框开关
  70. let modelIds = ref('')//模型id
  71. let iedTypes = ref('')//iedtype
  72. let addModal = ref(false)//新增功能模态框开关状态
  73. let delModal = ref(false)//删除功能模态框开关状态
  74. let tableData = ref([])//表格数据
  75. let editOrAdd = ref(0)//0为新增,1为编辑
  76. let editRow = ref({})//编辑的对象
  77. let delFcda = ref("")//需要删除的fcda_id
  78. watch(() => props.modelId, (newVal) => {
  79. modelIds.value = newVal
  80. })
  81. watch(() => props.iedType, (newVal) => {
  82. iedTypes.value = newVal
  83. })
  84. // 初始化函数
  85. function reload() {
  86. dialogVisible.value = props.abModal
  87. modelIds.value = props.modelId
  88. iedTypes.value = props.iedType
  89. flow.getModelAndIed({//获取所有功能
  90. model_id: modelIds.value - 0,
  91. ied_type: iedTypes.value
  92. }).then(res => {
  93. tableData.value = res.data
  94. })
  95. }
  96. function downloadFile() {
  97. const fileUrl = '../../../../public/fanc_comp.xlsx'; // 修改为绝对路径
  98. fetch(fileUrl)
  99. .then(response => {
  100. if (!response.ok) {
  101. throw new Error('Network response was not ok');
  102. }
  103. return response.blob();
  104. })
  105. .then(blob => {
  106. const url = window.URL.createObjectURL(blob);
  107. const a = document.createElement('a');
  108. a.download = 'fanc_comp.xlsx'; // 修改文件名
  109. a.href = url;
  110. document.body.appendChild(a);
  111. a.click();
  112. a.remove();
  113. window.URL.revokeObjectURL(url);
  114. })
  115. .catch(error => {
  116. console.error('There was a problem with the fetch operation:', error);
  117. });
  118. }
  119. // 下载报告模板
  120. function lookTemplate() {
  121. // 84780
  122. system.downLoad({ ids: 84780 }).then(res => {
  123. if (res.code == 0) {//使用接口获取服务器上文件位置
  124. let a = window.ApiServer + res.data//合成链接
  125. window.location = a//调用原生链接下载文件
  126. }
  127. })
  128. }
  129. // 文件上传
  130. function upTemplate(e) {
  131. // 调用接口进行文件上传
  132. flow.excelInData({ code: "ied_func_fcda", file: e.file, model_id: modelIds.value - 0 }).then(res => {
  133. if (res.returncode == 200) {
  134. ElMessage({
  135. message: "上传成功!",
  136. type: "success"
  137. })
  138. flow.getModelAndIed({//获取所有功能
  139. model_id: modelIds.value - 0,
  140. ied_type: iedTypes.value
  141. }).then(res => {
  142. tableData.value = res.data
  143. })
  144. } else {
  145. ElMessage({
  146. message: res.msg,
  147. type: "error"
  148. })
  149. }
  150. })
  151. }
  152. function copyReload() {
  153. flow.getModelAndIed({//获取所有功能
  154. model_id: modelIds.value - 0,
  155. ied_type: iedTypes.value
  156. }).then(res => {
  157. tableData.value = res.data
  158. })
  159. }
  160. // 关闭模态框
  161. function closeModal() {
  162. dialogVisible.value = false//赋值为false关闭模态框
  163. emit("abilityBack", dialogVisible.value)//返回给组件状态
  164. }
  165. // 确认后关闭模态框
  166. function sureClose() {
  167. dialogVisible.value = false//赋值为false关闭模态框
  168. emit("abilityBack", dialogVisible.value)//返回给组件状态
  169. }
  170. // 打开新增或编辑模态框
  171. function addAbility(num, row) {
  172. editOrAdd.value = num
  173. editRow.value = row
  174. addModal.value = true
  175. }
  176. // 删除功能
  177. function delAbility(row) {
  178. delFcda.value = row.id
  179. delModal.value = true
  180. }
  181. // 确认删除功能
  182. function firmSure() {
  183. }
  184. function addAback(data) {
  185. addModal.value = data
  186. }
  187. function delBack(data) {
  188. delModal.value = data
  189. }
  190. onMounted(() => {
  191. reload()
  192. })
  193. return {
  194. dialogVisible,//模态框开关
  195. reload,//初始化组件
  196. handleClose: closeModal,//关闭模态框
  197. cancels: closeModal,//关闭模态框
  198. sureClick: sureClose,//确认后关闭模态框
  199. addModal,//新增功能模态框开关状态
  200. addAbility,//打开新增功能模态框
  201. addAback,//AddAbility.vue返回模态框状态
  202. tableData,//表格数据
  203. modelIds,//本组件需要的模型id
  204. iedTypes,//本组件需要的iedtypes
  205. copyReload,//给addability.vue准备的方法
  206. delAbility,//删除功能
  207. firmSure,//确认删除功能
  208. editOrAdd,//0为新增,1为编辑
  209. editRow,//编辑的对象
  210. delFcda,//需要删除的fcdaid
  211. delModal,//删除功能模态框开关状态
  212. delBack,//DelAbility.vue返回模态框状态
  213. lookTemplate,//模板下载
  214. upTemplate,//文件上传
  215. downloadFile,
  216. }
  217. },
  218. components: {
  219. AddAbility,//嵌套新增功能窗口
  220. DelAbility,//嵌套删除模态框
  221. }
  222. }
  223. </script>
  224. <style scoped></style>