locationColumns.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { ref } from "vue";
  2. import { delObjectProperty } from "@pureadmin/utils";
  3. import Location from "@/model/location.js";
  4. export function useLocationColumns() {
  5. const locationEditMap = ref({});
  6. const locationDataList = ref([]);
  7. const locationColumns: TableColumnList = [
  8. {
  9. label: "ID",
  10. prop: "id",
  11. width: 100,
  12. cellRenderer: ({ row, index }) => (
  13. <>
  14. {locationEditMap.value[index]?.editable ? (
  15. <el-input v-model={row.id} />
  16. ) : (
  17. <p>{row.id}</p>
  18. )}
  19. </>
  20. )
  21. },
  22. {
  23. label: "名称",
  24. prop: "name",
  25. width: 170,
  26. cellRenderer: ({ row, index }) => (
  27. <>
  28. {locationEditMap.value[index]?.editable ? (
  29. <el-input v-model={row.name} />
  30. ) : (
  31. <p>{row.name}</p>
  32. )}
  33. </>
  34. )
  35. },
  36. {
  37. label: "中心坐标",
  38. prop: "center",
  39. cellRenderer: ({ row, index }) => (
  40. <>
  41. {locationEditMap.value[index]?.editable ? (
  42. <div>
  43. <span>经度:</span>
  44. <el-input style="width: 150px;" v-model={row.center.x} >
  45. </el-input>
  46. <span>纬度:</span>
  47. <el-input style="width: 150px;" v-model={row.center.y} >
  48. </el-input>
  49. </div>
  50. ) : (
  51. <p>{'经度:[' + row.center.x + '],纬度:[' + row.center.y + ']'}</p>
  52. )}
  53. </>
  54. )
  55. },
  56. {
  57. label: "操作",
  58. fixed: "right",
  59. width: 140,
  60. slot: "operation"
  61. }
  62. ];
  63. function onEditLocation(row, index) {
  64. locationEditMap.value[index] = Object.assign({ ...row, editable: true });
  65. }
  66. function onSaveLocation(index) {
  67. locationEditMap.value[index].editable = false;
  68. }
  69. function onCancelLocation(index) {
  70. locationEditMap.value[index].editable = false;
  71. locationDataList.value[index] = delObjectProperty(locationEditMap.value[index], "editable");
  72. }
  73. function onAddLocation() {
  74. const v = new Location();
  75. v.id = locationDataList.value.length + 1;
  76. locationDataList.value.push(v);
  77. }
  78. function onDelLocation(row) {
  79. const index = locationDataList.value.indexOf(row);
  80. if (index !== -1) locationDataList.value.splice(index, 1);
  81. }
  82. return {
  83. locationEditMap,
  84. locationColumns,
  85. locationDataList,
  86. onAddLocation,
  87. onDelLocation,
  88. onEditLocation,
  89. onSaveLocation,
  90. onCancelLocation
  91. };
  92. }