WorkFacePointTable.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <div class="p-4">
  3. <div class="btm-group vent-flex-row-between">
  4. <div>
  5. <label style="color: #fff">设备类型:</label>
  6. <ApiTreeSelect
  7. @change="handleChange"
  8. :api="deviceList.bind(null, { devicetype: '' })"
  9. :fieldNames="{ children: 'children', label: 'itemText', value: 'itemValue' }"
  10. v-model:value="deviceKind"
  11. style="width: 200px"
  12. />
  13. <a-button type="primary" @click="addRow"> 新增 </a-button>
  14. </div>
  15. <a-button class="vent-margin-l-10" type="primary" @click="handleSave()"> 批量保存 </a-button>
  16. </div>
  17. <div class="monitor-nav">
  18. <div class="device-button-group" v-if="relevanceDeviceData.length > 0">
  19. <div class="device-button" :class="{ 'device-active': deviceActive == device.type }" v-for="(device, index) in relevanceDeviceData" :key="index" @click="deviceChange(index)">{{ device.typeName }}</div>
  20. </div>
  21. </div>
  22. <BasicTable ref="editTable" @register="registerTable" :dataSource="dataSource" :columns="workFaceColumns" @edit-change="onEditChange" v-if="refresh">
  23. <template #action="{ record, column }">
  24. <TableAction :actions="createActions(record, column)" />
  25. </template>
  26. </BasicTable>
  27. <DeviceModalTable
  28. @register="registerModal"
  29. :deviceType="deviceKind"
  30. :deviceID="deviceId"
  31. @reload="getWorkFaceList"
  32. :selectionRowKeys="selectionRowKeys"
  33. />
  34. </div>
  35. </template>
  36. <script lang="ts">
  37. import { defineComponent, ref, nextTick, inject, onMounted } from 'vue';
  38. import { BasicTable, useTable, TableAction, BasicColumn, ActionItem, EditRecordRow } from '/@/components/Table';
  39. import { useModal } from '/@/components/Modal';
  40. import { ApiTreeSelect } from '/@/components/Form';
  41. import DeviceModalTable from './DeviceModalTable.vue';
  42. import { deviceId, workDeviceList, deviceList, list, edit, workDeviceEdit, workRelevanceDeviceTypes, workRelevanceDeviceDelete } from './point.api';
  43. import { workFaceColumns, deviceColumns } from './point.data';
  44. type RelevanceDeviceType = {
  45. datalist: [],
  46. type: string,
  47. typeName: string
  48. }
  49. export default defineComponent({
  50. components: { BasicTable, TableAction, DeviceModalTable, ApiTreeSelect },
  51. props: {
  52. columns: {
  53. type: Array,
  54. requried: true,
  55. },
  56. deviceId: {
  57. type: String || Number,
  58. requried: true,
  59. },
  60. list: {
  61. type: Function,
  62. requried: true,
  63. },
  64. isAdd: {
  65. type: Boolean,
  66. },
  67. },
  68. emits: ['save', 'delete'],
  69. setup(props, { emit }) {
  70. const editTable = ref<any>(null);
  71. const activeTab = ref('1');
  72. const deviceKind = ref('');
  73. const type = inject('deviceType') || '';
  74. const refresh = ref(true)
  75. const currentEditKeyRef = ref('');
  76. const options = ref([]);
  77. const dataSource = ref<any>([]);
  78. const selectionRowKeys = ref<any[]>([]);
  79. const relevanceDeviceData = ref<RelevanceDeviceType[]>([])
  80. const deviceNavData = ref<any[]>([]) // 关联设备
  81. const deviceActive = ref('') // 激活状态下的设备
  82. const [registerModal, { openModal }] = useModal();
  83. const [registerTable, { insertTableDataRecord, reload }] = useTable({
  84. title: '',
  85. showIndexColumn: true,
  86. showTableSetting: false,
  87. tableSetting: { fullScreen: true },
  88. actionColumn: {
  89. width: 160,
  90. title: '操作',
  91. dataIndex: 'action',
  92. slots: { customRender: 'action' },
  93. },
  94. });
  95. async function getDeviceNavData() {
  96. relevanceDeviceData.value = await workRelevanceDeviceTypes({ id: props.deviceId })
  97. deviceChange(0)
  98. }
  99. function addRow() {
  100. openModal();
  101. }
  102. function handleEdit(record: EditRecordRow) {
  103. currentEditKeyRef.value = record.key;
  104. record.onEdit?.(true);
  105. }
  106. function handleCancel(record: EditRecordRow) {
  107. currentEditKeyRef.value = '';
  108. record.onEdit?.(false, false);
  109. }
  110. function handleDelete(record: EditRecordRow) {
  111. debugger
  112. emit('delete', record.id, reload);
  113. }
  114. async function getOptions() {
  115. const res = await deviceList({ devicetype: '' });
  116. options.value = res;
  117. }
  118. function getWorkFaceList() {
  119. deviceActive.value = deviceKind.value
  120. handleSuccess()
  121. }
  122. function deviceChange(index) {
  123. deviceActive.value = relevanceDeviceData.value[index].type
  124. dataSource.value = relevanceDeviceData.value[index].datalist
  125. }
  126. function handleChange(value, label, extra) {
  127. console.log('树节点选中------>',value, label, extra)
  128. deviceKind.value = value;
  129. const activeData = relevanceDeviceData.value.find(item => {
  130. return item.type === value
  131. })
  132. if(activeData){
  133. deviceActive.value = activeData.type
  134. dataSource.value = activeData.datalist
  135. }else{
  136. deviceActive.value = ''
  137. dataSource.value = []
  138. }
  139. }
  140. async function handleSave(record?: EditRecordRow) {
  141. if (record) {
  142. dataSource.value.filter((item) => {
  143. if (record.id && record.id === item.id) {
  144. Object.assign(item, record.editValueRefs);
  145. }
  146. });
  147. console.log('[ dataSource ] >', dataSource.value, record);
  148. // 校验
  149. await edit(dataSource.value);
  150. record.onEdit?.(false);
  151. refresh.value = false
  152. } else {
  153. //workDeviceEdit
  154. if (editTable.value && editTable?.value.getDataSource) {
  155. const arr: any[] = [];
  156. const dataList = editTable?.value.getDataSource();
  157. const ids = <any[]>[];
  158. dataList.forEach((element) => {
  159. arr.push(Object.assign(element, element.editValueRefs));
  160. ids.push(element.deviceId)
  161. });
  162. dataSource.value = dataList;
  163. // await workDeviceEdit({ deviceKind : deviceKind.value, ids: ids, sysid: props.deviceId }, handleSuccess)
  164. await edit(dataSource.value);
  165. }
  166. }
  167. nextTick(() => {
  168. refresh.value = true
  169. clearSelectedRowKeys()
  170. })
  171. }
  172. async function handleSuccess() {
  173. relevanceDeviceData.value = await workRelevanceDeviceTypes({ id: props.deviceId })
  174. handleChange(deviceActive.value)
  175. }
  176. function createActions(record: EditRecordRow, column: BasicColumn): ActionItem[] {
  177. if (!record.editable) {
  178. if (props.isAdd) {
  179. return [
  180. {
  181. label: '编辑',
  182. disabled: currentEditKeyRef.value ? currentEditKeyRef.value !== record.key : false,
  183. onClick: handleEdit.bind(null, record),
  184. },
  185. {
  186. label: '删除',
  187. disabled: currentEditKeyRef.value ? currentEditKeyRef.value !== record.key : false,
  188. onClick: handleDelete.bind(null, record),
  189. },
  190. ];
  191. } else {
  192. return [
  193. {
  194. label: '编辑',
  195. disabled: currentEditKeyRef.value ? currentEditKeyRef.value !== record.key : false,
  196. onClick: handleEdit.bind(null, record),
  197. },
  198. {
  199. label: '删除',
  200. onClick: workRelevanceDeviceDelete.bind(null, { deviceid: record.deviceID, sysid: props.deviceId }, handleSuccess),
  201. },
  202. ];
  203. }
  204. }
  205. return [
  206. {
  207. label: '保存',
  208. onClick: handleSave.bind(null, record, column),
  209. },
  210. {
  211. label: '取消',
  212. popConfirm: {
  213. title: '是否取消编辑',
  214. confirm: handleCancel.bind(null, record, column),
  215. },
  216. },
  217. ];
  218. }
  219. function onEditChange({ column, value, record }) {
  220. // 本例
  221. if (column.dataIndex === 'devicetype') {
  222. // record.editValueRefs.name4.value = `${value}`;
  223. }
  224. // console.log(column, value, record);
  225. }
  226. onMounted(async () => {
  227. await getOptions();
  228. await getDeviceNavData()
  229. // getWorkFaceList();
  230. });
  231. return {
  232. editTable,
  233. activeTab,
  234. refresh,
  235. registerTable,
  236. handleEdit,
  237. createActions,
  238. onEditChange,
  239. addRow,
  240. workFaceColumns,
  241. deviceColumns,
  242. getOptions,
  243. options,
  244. deviceList,
  245. dataSource,
  246. deviceKind,
  247. handleChange,
  248. registerModal,
  249. handleSave,
  250. selectionRowKeys,
  251. getWorkFaceList,
  252. relevanceDeviceData,
  253. deviceNavData,
  254. deviceActive,
  255. deviceChange,
  256. // handleChangeDeviceType,
  257. // handleChangeLinkCode,
  258. // monitorParamsOptions,
  259. };
  260. },
  261. });
  262. </script>
  263. <style scoped lang="less">
  264. @ventSpace: zxm;
  265. :deep(.@{ventSpace}-table-body) {
  266. height: auto !important;
  267. }
  268. .btm-group {
  269. padding-bottom: 2px;
  270. }
  271. .device-button-group{
  272. // margin: 0 20px;
  273. display: flex;
  274. flex-wrap: wrap;
  275. pointer-events: auto;
  276. position: relative;
  277. margin-top: 10px;
  278. margin-bottom: 5px;
  279. &::after{
  280. position:absolute;
  281. content: '';
  282. width: calc(100% + 10px);
  283. height: 2px;
  284. top: 30px;
  285. left: -10px;
  286. border-bottom: 1px solid #0efcff;
  287. }
  288. .device-button{
  289. padding: 4px 10px;
  290. position: relative;
  291. display: flex;
  292. justify-content: center;
  293. align-items: center;
  294. font-size: 14px;
  295. color: #fff;
  296. cursor: pointer;
  297. margin: 0 1px;
  298. &::before{
  299. content: '';
  300. position: absolute;
  301. top: 0;
  302. right: 0;
  303. bottom: 0;
  304. left: 0;
  305. border: 1px solid #6176AF;
  306. // transform: skewX(-38deg);
  307. background-color: rgba(0, 77, 103,85%);
  308. z-index: -1;
  309. }
  310. }
  311. .device-active{
  312. // color: #0efcff;
  313. &::before{
  314. border-color: #0efcff;
  315. box-shadow: 1px 1px 3px 1px #0efcff inset;
  316. }
  317. }
  318. }
  319. </style>