columns.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import type {
  2. LoadingConfig,
  3. AdaptiveConfig,
  4. PaginationProps
  5. } from "@pureadmin/table";
  6. import { ref, reactive } from "vue";
  7. import { delObjectProperty } from "@pureadmin/utils";
  8. import { clone, delay } from "@pureadmin/utils";
  9. import Project from "@/model/project.js";
  10. export function useColumns() {
  11. const loading = ref(true);
  12. const editMap = ref({});
  13. const dataList = ref([]);
  14. const options = ref([
  15. {
  16. value: 0,
  17. label: "未开始",
  18. type: "info"
  19. },
  20. {
  21. value: 1,
  22. label: "进行中",
  23. type: ""
  24. },
  25. {
  26. value: 2,
  27. label: "已完成",
  28. type: "success"
  29. }
  30. ]);
  31. const columns: TableColumnList = [
  32. {
  33. label: "ID",
  34. prop: "id",
  35. cellRenderer: ({ row, index }) => (
  36. <>
  37. {editMap.value[index]?.editable ? (
  38. <el-input v-model={row.id} />
  39. ) : (
  40. <p>{row.id}</p>
  41. )}
  42. </>
  43. )
  44. },
  45. {
  46. label: "项目名称",
  47. prop: "name",
  48. cellRenderer: ({ row, index }) => (
  49. <>
  50. {editMap.value[index]?.editable ? (
  51. <el-input v-model={row.name} />
  52. ) : (
  53. <p>{row.name}</p>
  54. )}
  55. </>
  56. )
  57. },
  58. {
  59. label: "项目版本",
  60. prop: "version",
  61. cellRenderer: ({ row, index }) => (
  62. <>
  63. {editMap.value[index]?.editable ? (
  64. <el-input v-model={row.version} />
  65. ) : (
  66. <p>{row.version}</p>
  67. )}
  68. </>
  69. )
  70. },
  71. {
  72. label: "区域数量",
  73. prop: "locations",
  74. cellRenderer: ({ row, index }) => (
  75. <p>{row.locations.length}</p>
  76. )
  77. },
  78. {
  79. label: "人员数量",
  80. prop: "persons",
  81. cellRenderer: ({ row, index }) => (
  82. <p>{row.persons.length}</p>
  83. )
  84. },
  85. {
  86. label: "项目状态",
  87. prop: "status",
  88. cellRenderer: ({ row, index }) => (
  89. <el-tag type={options.value.filter(opt => opt.value == row.status)[0]?.type}>
  90. {options.value.filter(opt => opt.value == row.status)[0]?.label}
  91. </el-tag>
  92. )
  93. },
  94. {
  95. label: "操作",
  96. fixed: "right",
  97. slot: "operation"
  98. }
  99. ];
  100. /** 分页配置 */
  101. const pagination = reactive<PaginationProps>({
  102. pageSize: 20,
  103. currentPage: 1,
  104. pageSizes: [20, 40, 60],
  105. total: 0,
  106. align: "right",
  107. background: true,
  108. size: "default"
  109. });
  110. /** 加载动画配置 */
  111. const loadingConfig = reactive<LoadingConfig>({
  112. text: "正在加载第一页...",
  113. viewBox: "-10, -10, 50, 50",
  114. spinner: `
  115. <path class="path" d="
  116. M 30 15
  117. L 28 17
  118. M 25.61 25.61
  119. A 15 15, 0, 0, 1, 15 30
  120. A 15 15, 0, 1, 1, 27.99 7.5
  121. L 15 15
  122. " style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>
  123. `
  124. // svg: "",
  125. // background: rgba()
  126. });
  127. /** 撑满内容区自适应高度相关配置 */
  128. const adaptiveConfig: AdaptiveConfig = {
  129. /** 表格距离页面底部的偏移量,默认值为 `96` */
  130. offsetBottom: 110
  131. /** 是否固定表头,默认值为 `true`(如果不想固定表头,fixHeader设置为false并且表格要设置table-layout="auto") */
  132. // fixHeader: true
  133. /** 页面 `resize` 时的防抖时间,默认值为 `60` ms */
  134. // timeout: 60
  135. /** 表头的 `z-index`,默认值为 `100` */
  136. // zIndex: 100
  137. };
  138. function onSizeChange(val) {
  139. console.log("onSizeChange", val);
  140. }
  141. function onCurrentChange(val) {
  142. loadingConfig.text = `正在加载第${val}页...`;
  143. loading.value = true;
  144. delay(600).then(() => {
  145. loading.value = false;
  146. });
  147. }
  148. function onEdit(row, index) {
  149. editMap.value[index] = Object.assign({ ...row, editable: true });
  150. }
  151. function onSave(index) {
  152. editMap.value[index].editable = false;
  153. }
  154. function onCancel(index) {
  155. editMap.value[index].editable = false;
  156. dataList.value[index] = delObjectProperty(editMap.value[index], "editable");
  157. }
  158. function onAdd() {
  159. const v = new Project();
  160. v.id = dataList.value.length + 1;
  161. dataList.value.push(v);
  162. }
  163. function onDel(row) {
  164. const index = dataList.value.indexOf(row);
  165. if (index !== -1) dataList.value.splice(index, 1);
  166. }
  167. return {
  168. loading,
  169. editMap,
  170. columns,
  171. dataList,
  172. options,
  173. pagination,
  174. loadingConfig,
  175. adaptiveConfig,
  176. onAdd,
  177. onDel,
  178. onEdit,
  179. onSave,
  180. onCancel,
  181. onSizeChange,
  182. onCurrentChange
  183. };
  184. }