index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <el-card>
  3. <template #header>
  4. <div
  5. v-if="useUserStoreHook().existsRole(['opt', 'admin', 'eng', 'root'])"
  6. class="card-header"
  7. >
  8. <!-- <span style="margin-right: 10px;">
  9. 启用编辑
  10. <el-switch
  11. v-model="swEditable"
  12. class="ml-2"
  13. inline-prompt
  14. style="--el-switch-off-color: #666666"
  15. />
  16. </span> -->
  17. <el-button :icon="useRenderIcon(AddFill)" @click="handleAddProject">
  18. 添加项目
  19. </el-button>
  20. </div>
  21. </template>
  22. <div>
  23. <pure-table
  24. row-key="id"
  25. align-whole="center"
  26. :header-cell-style="{
  27. background: 'var(--el-fill-color-light)',
  28. color: 'var(--el-text-color-primary)'
  29. }"
  30. :columns="columns"
  31. :table-key="tableKey"
  32. border
  33. adaptive
  34. :adaptiveConfig="adaptiveConfig"
  35. showOverflowTooltip
  36. :loading="false"
  37. :loading-config="loadingConfig"
  38. :data="
  39. dataList.slice(
  40. (pagination.currentPage - 1) * pagination.pageSize,
  41. pagination.currentPage * pagination.pageSize
  42. )
  43. "
  44. :pagination="pagination"
  45. @page-size-change="onSizeChange"
  46. @page-current-change="onCurrentChange"
  47. >
  48. <template #operation="{ row, index }">
  49. <div v-if="!editMap[index]?.editable">
  50. <el-button
  51. v-if="
  52. useUserStoreHook().existsRole(['opt', 'admin', 'eng', 'root'])
  53. "
  54. class="reset-margin"
  55. link
  56. type="primary"
  57. :icon="useRenderIcon(Delete)"
  58. @click="handleDeleteProject(row)"
  59. >
  60. 删除
  61. </el-button>
  62. <el-button
  63. v-if="
  64. useUserStoreHook().existsRole(['opt', 'admin', 'eng', 'root'])
  65. "
  66. class="reset-margin"
  67. link
  68. type="primary"
  69. @click="handleEditProject(row)"
  70. :icon="useRenderIcon(EditFill)"
  71. >
  72. 修改
  73. </el-button>
  74. <el-button
  75. class="reset-margin"
  76. link
  77. type="primary"
  78. :icon="useRenderIcon(OpenPreview)"
  79. @click="handleViewProject(row)"
  80. >
  81. 查看
  82. </el-button>
  83. </div>
  84. <div v-if="editMap[index]?.editable">
  85. <el-button
  86. class="reset-margin"
  87. link
  88. type="primary"
  89. @click="onSave(index)"
  90. :icon="useRenderIcon(SaveFill)"
  91. >
  92. 保存
  93. </el-button>
  94. <el-button
  95. class="reset-margin"
  96. link
  97. @click="onCancel(index)"
  98. :icon="useRenderIcon(Close)"
  99. >
  100. 取消
  101. </el-button>
  102. </div>
  103. </template>
  104. </pure-table>
  105. </div>
  106. <el-dialog
  107. v-model="dlgAddProjectVisible"
  108. title="项目信息"
  109. width="60%"
  110. :before-close="handleDlgClose"
  111. destroy-on-close
  112. top="6vh"
  113. >
  114. <EditProject
  115. :selProject="selProject"
  116. :swEditable="swEditable"
  117. @onSubmitData="onSubmitProjectData"
  118. />
  119. <!-- <template #footer>
  120. <span class="dialog-footer">
  121. <el-button @click="dlgAddProjectVisible = false">取消</el-button>
  122. <el-button type="primary" @click="handleDlgConfirm">
  123. 导入
  124. </el-button>
  125. </span>
  126. </template> -->
  127. </el-dialog>
  128. </el-card>
  129. </template>
  130. <script setup lang="ts">
  131. import { ref, onMounted } from "vue";
  132. import { useColumns } from "./columns";
  133. import Empty from "../empty.svg?component";
  134. import { useRenderIcon } from "@/components/ReIcon/src/hooks";
  135. import AddFill from "~icons/ep/plus";
  136. import Delete from "~icons/ep/delete";
  137. import EditFill from "~icons/ep/edit";
  138. import SaveFill from "~icons/bi/save";
  139. import Close from "~icons/ep/close";
  140. import OpenPreview from "~icons/codicon/open-preview";
  141. import { ElMessage, ElMessageBox, ElNotification } from "element-plus";
  142. import * as XLSX from "xlsx";
  143. import importExcel from "./importExcel.vue";
  144. import EditProject from "./edit.vue";
  145. import Project from "@/model/project.js";
  146. import { useUserStoreHook } from "@/store/modules/user";
  147. const {
  148. loading,
  149. editMap,
  150. columns,
  151. dataList,
  152. options,
  153. pagination,
  154. loadingConfig,
  155. adaptiveConfig,
  156. onSave,
  157. onCancel,
  158. onDel,
  159. onSizeChange,
  160. onCurrentChange
  161. } = useColumns();
  162. const swEditable = ref(true);
  163. const tableKey = ref(0);
  164. const vGlobal = window.vueGlobal;
  165. const dlgAddProjectVisible = ref(false);
  166. const selProject = ref(new Project());
  167. const reloadProjects = () => {
  168. vGlobal.refreshProjects(() => {
  169. dataList.value = [];
  170. dataList.value = vGlobal.vecProject.filter(item => item.status != 2); // 深拷贝,触发视图更新
  171. console.log("reloadProjects", dataList.value);
  172. tableKey.value += 1;
  173. pagination.total = dataList.value.length;
  174. });
  175. };
  176. const handleAddProject = () => {
  177. swEditable.value = true;
  178. selProject.value = new Project();
  179. selProject.value.isCreate = true;
  180. dlgAddProjectVisible.value = true;
  181. };
  182. const handleEditProject = (row: Project) => {
  183. swEditable.value = true;
  184. selProject.value = new Project(row);
  185. selProject.value.isCreate = false;
  186. dlgAddProjectVisible.value = true;
  187. };
  188. const handleViewProject = (row: Project) => {
  189. swEditable.value = false;
  190. selProject.value = new Project(row);
  191. dlgAddProjectVisible.value = true;
  192. };
  193. const handleDeleteProject = (row: Project) => {
  194. ElMessageBox.confirm("确定删除项目?删除后将无法撤回", "Warning", {
  195. confirmButtonText: "确认",
  196. cancelButtonText: "取消",
  197. type: "warning"
  198. })
  199. .then(() => {
  200. vGlobal.deleteProject(row, () => {
  201. ElNotification.success({
  202. message: "删除成功"
  203. });
  204. reloadProjects();
  205. });
  206. })
  207. .catch(() => {});
  208. };
  209. const onSubmitProjectData = (data: Project) => {
  210. const proj = new Project(data);
  211. ElMessageBox.confirm("确定更新项目数据?更新后将无法撤回", "Warning", {
  212. confirmButtonText: "确认",
  213. cancelButtonText: "取消",
  214. type: "warning"
  215. })
  216. .then(() => {
  217. for (const p of vGlobal.vecProject) {
  218. if (p.id == proj.id && proj.isCreate) {
  219. ElNotification.warning({
  220. message: "已存在相同ID的项目,ID为[" + p.id + "]"
  221. });
  222. return;
  223. }
  224. }
  225. ElNotification.info({
  226. message: "开始更新"
  227. });
  228. vGlobal.updateProject(proj, () => {
  229. ElNotification.success({
  230. message: "更新成功"
  231. });
  232. reloadProjects();
  233. dlgAddProjectVisible.value = false;
  234. });
  235. })
  236. .catch(() => {
  237. // ElMessage({
  238. // type: 'info',
  239. // message: 'Delete canceled',
  240. // })
  241. });
  242. };
  243. const handleDlgClose = (done: () => void) => {
  244. ElMessageBox.confirm("确定要关闭这个对话框吗?")
  245. .then(() => {
  246. done();
  247. })
  248. .catch(() => {
  249. // catch error
  250. });
  251. };
  252. onMounted(() => {
  253. reloadProjects();
  254. });
  255. </script>