WorkFacePointTable.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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="columns" @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, watch } 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, 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: <any>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 linkColumns = ref(props.columns)
  80. const relevanceDeviceData = ref<RelevanceDeviceType[]>([])
  81. const deviceNavData = ref<any[]>([]) // 关联设备
  82. const deviceActive = ref('') // 激活状态下的设备
  83. const [registerModal, { openModal }] = useModal();
  84. const [registerTable, { insertTableDataRecord, setColumns }] = useTable(
  85. {
  86. title: '',
  87. showIndexColumn: true,
  88. showTableSetting: false,
  89. tableSetting: { fullScreen: true },
  90. actionColumn: {
  91. width: 160,
  92. title: '操作',
  93. dataIndex: 'action',
  94. slots: { customRender: 'action' },
  95. },
  96. }
  97. );
  98. async function getDeviceNavData() {
  99. relevanceDeviceData.value = await workRelevanceDeviceTypes({ id: props.deviceId })
  100. deviceChange(0)
  101. }
  102. function addRow() {
  103. openModal();
  104. }
  105. function handleEdit(record: EditRecordRow) {
  106. currentEditKeyRef.value = record.key;
  107. record.onEdit?.(true);
  108. }
  109. function handleCancel(record: EditRecordRow) {
  110. currentEditKeyRef.value = '';
  111. record.onEdit?.(false, false);
  112. }
  113. function handleDelete(record: EditRecordRow) {
  114. emit('delete', record.id, reload);
  115. }
  116. async function getOptions() {
  117. const res = await deviceList({ devicetype: '' });
  118. options.value = res;
  119. }
  120. function getWorkFaceList() {
  121. deviceActive.value = deviceKind.value
  122. handleSuccess()
  123. }
  124. function deviceChange(index) {
  125. deviceActive.value = relevanceDeviceData.value[index].type
  126. dataSource.value = relevanceDeviceData.value[index].datalist
  127. }
  128. function handleChange(value, label, extra) {
  129. console.log('树节点选中------>',value, label, extra)
  130. deviceKind.value = value;
  131. const activeData = relevanceDeviceData.value.find(item => {
  132. return item.type === value
  133. })
  134. if(activeData){
  135. deviceActive.value = activeData.type
  136. dataSource.value = activeData.datalist
  137. }else{
  138. deviceActive.value = ''
  139. dataSource.value = []
  140. }
  141. }
  142. async function handleSave(record?: EditRecordRow) {
  143. if (record) {
  144. dataSource.value.filter((item) => {
  145. if (record.id && record.id === item.id) {
  146. Object.assign(item, record.editValueRefs);
  147. }
  148. });
  149. console.log('[ dataSource ] >', dataSource.value, record);
  150. // 校验
  151. await edit(dataSource.value);
  152. record.onEdit?.(false);
  153. refresh.value = false
  154. } else {
  155. //workDeviceEdit
  156. if (editTable.value && editTable?.value.getDataSource) {
  157. const arr: any[] = [];
  158. const dataList = editTable?.value.getDataSource();
  159. const ids = <any[]>[];
  160. dataList.forEach((element) => {
  161. arr.push(Object.assign(element, element.editValueRefs));
  162. ids.push(element.deviceId)
  163. });
  164. dataSource.value = dataList;
  165. // await workDeviceEdit({ deviceKind : deviceKind.value, ids: ids, sysid: props.deviceId }, handleSuccess)
  166. await edit(dataSource.value);
  167. }
  168. }
  169. nextTick(() => {
  170. refresh.value = true
  171. clearSelectedRowKeys()
  172. })
  173. }
  174. async function handleSuccess() {
  175. relevanceDeviceData.value = await workRelevanceDeviceTypes({ id: props.deviceId })
  176. handleChange(deviceActive.value)
  177. }
  178. function createActions(record: EditRecordRow, column: BasicColumn): ActionItem[] {
  179. if (!record.editable) {
  180. if (props.isAdd) {
  181. return [
  182. {
  183. label: '编辑',
  184. disabled: currentEditKeyRef.value ? currentEditKeyRef.value !== record.key : false,
  185. onClick: handleEdit.bind(null, record),
  186. },
  187. {
  188. label: '删除',
  189. disabled: currentEditKeyRef.value ? currentEditKeyRef.value !== record.key : false,
  190. onClick: handleDelete.bind(null, record),
  191. },
  192. ];
  193. } else {
  194. return [
  195. {
  196. label: '编辑',
  197. disabled: currentEditKeyRef.value ? currentEditKeyRef.value !== record.key : false,
  198. onClick: handleEdit.bind(null, record),
  199. },
  200. {
  201. label: '删除',
  202. onClick: workRelevanceDeviceDelete.bind(null, { deviceid: record.deviceId, sysid: props.deviceId }, handleSuccess),
  203. },
  204. ];
  205. }
  206. }
  207. return [
  208. {
  209. label: '保存',
  210. onClick: handleSave.bind(null, record, column),
  211. },
  212. {
  213. label: '取消',
  214. popConfirm: {
  215. title: '是否取消编辑',
  216. confirm: handleCancel.bind(null, record, column),
  217. },
  218. },
  219. ];
  220. }
  221. function onEditChange({ column, value, record }) {
  222. // 本例
  223. if (column.dataIndex === 'devicetype') {
  224. // record.editValueRefs.name4.value = `${value}`;
  225. }
  226. // console.log(column, value, record);
  227. }
  228. watch(() => props.columns, (columns) => {
  229. // linkColumns.value = columns
  230. // reload()
  231. setColumns(columns)
  232. })
  233. onMounted(async () => {
  234. await getOptions();
  235. await getDeviceNavData()
  236. // getWorkFaceList();
  237. });
  238. return {
  239. editTable,
  240. activeTab,
  241. refresh,
  242. registerTable,
  243. handleEdit,
  244. createActions,
  245. onEditChange,
  246. addRow,
  247. workFaceColumns,
  248. deviceColumns,
  249. getOptions,
  250. options,
  251. deviceList,
  252. dataSource,
  253. deviceKind,
  254. handleChange,
  255. registerModal,
  256. handleSave,
  257. selectionRowKeys,
  258. getWorkFaceList,
  259. relevanceDeviceData,
  260. deviceNavData,
  261. deviceActive,
  262. deviceChange,
  263. linkColumns
  264. // handleChangeDeviceType,
  265. // handleChangeLinkCode,
  266. // monitorParamsOptions,
  267. };
  268. },
  269. });
  270. </script>
  271. <style scoped lang="less">
  272. @ventSpace: zxm;
  273. :deep(.@{ventSpace}-table-body) {
  274. height: auto !important;
  275. }
  276. .btm-group {
  277. padding-bottom: 2px;
  278. }
  279. .device-button-group{
  280. // margin: 0 20px;
  281. display: flex;
  282. flex-wrap: wrap;
  283. pointer-events: auto;
  284. position: relative;
  285. margin-top: 10px;
  286. margin-bottom: 5px;
  287. &::after{
  288. position:absolute;
  289. content: '';
  290. width: calc(100% + 10px);
  291. height: 2px;
  292. top: 30px;
  293. left: -10px;
  294. border-bottom: 1px solid #0efcff;
  295. }
  296. .device-button{
  297. padding: 4px 10px;
  298. position: relative;
  299. display: flex;
  300. justify-content: center;
  301. align-items: center;
  302. font-size: 14px;
  303. color: #fff;
  304. cursor: pointer;
  305. margin: 0 1px;
  306. &::before{
  307. content: '';
  308. position: absolute;
  309. top: 0;
  310. right: 0;
  311. bottom: 0;
  312. left: 0;
  313. border: 1px solid #6176AF;
  314. // transform: skewX(-38deg);
  315. background-color: rgba(0, 77, 103,85%);
  316. z-index: -1;
  317. }
  318. }
  319. .device-active{
  320. // color: #0efcff;
  321. &::before{
  322. border-color: #0efcff;
  323. box-shadow: 1px 1px 3px 1px #0efcff inset;
  324. }
  325. }
  326. }
  327. </style>