index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <style scoped lang="scss">
  2. .system-container {
  3. :deep(.el-card__body) {
  4. display: flex;
  5. flex-direction: column;
  6. justify-content: space-between;
  7. flex: 1;
  8. overflow: auto;
  9. .el-table {
  10. flex: 1;
  11. }
  12. }
  13. }
  14. .page-content {
  15. margin-bottom: 20px;
  16. }
  17. .page-pager {
  18. background-color: var(--el-color-white);
  19. height: 24px;
  20. }
  21. </style>
  22. <template>
  23. <div class="system-container layout-padding">
  24. <el-card shadow="hover" class="layout-padding-auto">
  25. <ext-query-form
  26. class="page-search"
  27. ref="queryRef"
  28. v-model="state.formQuery"
  29. :columns="state.columns"
  30. @on-change="loadData(true)"
  31. @imported="loadData(true)">
  32. <template #extQuery>
  33. <el-button v-auth="'washDevice.add'" size="default" plain type="success" class="ml10" @click="handleRowClick('add',null)">
  34. <SvgIcon name="ele-FolderAdd"/>
  35. 新增
  36. </el-button>
  37. <el-button v-auth="'washDevice.modify'" size="default"
  38. plain type="success" class="ml10"
  39. @click="handleBatchDeviceConfig">
  40. <SvgIcon name="ele-Setting"/>
  41. 配置
  42. </el-button>
  43. </template>
  44. <!-- <template #extraQuery></template>
  45. <template #extraLeft></template>
  46. <template #extraRight></template>-->
  47. </ext-query-form>
  48. <ext-table
  49. selectable
  50. @on-check-change="handleChooseDeviceChange"
  51. class="page-content"
  52. :height="state.tableData.height"
  53. :data-list="state.tableData.data"
  54. :columns="state.columns"
  55. :border="true"
  56. :loading="state.tableData.loading">
  57. </ext-table>
  58. <ext-page class="page-pager" v-model:value="state.pageQuery" @change="loadData(false)"/>
  59. </el-card>
  60. </div>
  61. <DeviceDialog ref="device_dialog_ref" @refresh="loadData(true)"/>
  62. <DeviceConfigDialog ref="device_config_dialog_ref" @refresh="loadData(true)"/>
  63. </template>
  64. <script setup lang="ts" name="adminStationDevice">
  65. import {defineAsyncComponent, reactive, onMounted, onBeforeMount, ref, getCurrentInstance, nextTick, onBeforeUnmount} from 'vue';
  66. import {$body, $get} from "/@/utils/request";
  67. import u from '/@/utils/u'
  68. import {Msg} from "/@/utils/message";
  69. import {Session} from "/@/utils/storage";
  70. const {proxy}: any = getCurrentInstance();
  71. import ExtPage from '/@/components/form/ExtPage.vue'
  72. import ExtQueryForm from "/@/components/form/ExtQueryForm.vue";
  73. import ExtTable from "/@/components/form/ExtTable.vue";
  74. import mittBus from '/@/utils/mitt';
  75. import {ElButton} from 'element-plus'
  76. import DeviceDialog from '/@/views/admin/station/device/dialog.vue'
  77. import DeviceConfigDialog from '/@/views/admin/station/device/config.vue'
  78. //定义引用
  79. const queryRef = ref();
  80. const device_dialog_ref = ref();
  81. const device_config_dialog_ref = ref();
  82. //定义变量
  83. const state = reactive({
  84. chooseDeviceList: [],
  85. formQuery: {},
  86. pageQuery: {
  87. pageNum: 1,
  88. pageSize: 10,
  89. total: 0
  90. },
  91. tableData: {
  92. height: 500,
  93. data: [] as Array<any>,
  94. loading: false
  95. },
  96. importConfig: {},
  97. exportConfig: {},
  98. columns: [
  99. // {type: 'selection', width: 60, align: 'center', fixed: 'left'},
  100. {
  101. label: '站点',
  102. prop: 'stationId',
  103. width: 80,
  104. query: true,
  105. type: 'select',
  106. hide: true,
  107. resizable: true,
  108. conf: {url: 'washStation/list', labelKey: 'stationName', valueKey: 'stationId', dataKey: 'list'}
  109. },
  110. {label: '设备编号', prop: 'shortId', width: 100, query: true, type: 'text', resizable: true, fixed: 'left'},
  111. {
  112. label: '站点名称', prop: 'stationName', width: 180, query: false, type: 'render', resizable: true,
  113. render: (h: any, row: any, rowData: any) => {
  114. return (
  115. h('div', {
  116. class: 'flex-align-items-center text-align-center'
  117. }, [
  118. h("div", {}, rowData.stationId),
  119. h("hr"),
  120. h("div", {}, rowData.stationName)
  121. ])
  122. )
  123. }
  124. },
  125. // {label: '设备名称', prop: 'deviceName', width: 180, query: true, type: 'text', resizable: true, fixed: 'left'},
  126. // {label: '产品key', prop: 'productKey', width: 180, query: true, type: 'text', resizable: true},
  127. {label: '状态', prop: 'state', width: 90, query: true, type: 'dict', conf: {dict: 'WashDevice.status'}, resizable: true},
  128. // {label: '设备状态', prop: 'fsmState', width: 90, query: true, type: 'text', resizable: true},
  129. {
  130. label: '运行时长', prop: 'uptimeMs', width: 100, query: false, type: 'render', resizable: true,
  131. render: (h: any, row: any) => {
  132. return (
  133. h('div', null, u.fmt.fmtDuration(row))
  134. )
  135. }
  136. },
  137. {label: '功能', prop: 'functions', width: 180, query: true, type: 'text', resizable: true},
  138. {label: '是否有泡沫', prop: 'hasFoam', width: 180, query: true, type: 'dict', conf: {dict: 'WashDevice.foam'}, resizable: true},
  139. {label: '是否有水', prop: 'hasWater', width: 180, query: true, type: 'dict', conf: {dict: 'WashDevice.water'}, resizable: true},
  140. // {label: '当前温度', prop: 'temperatureChip', width: 180, query: false, type: 'text', resizable: true},
  141. {label: '创建时间', prop: 'createTime', query: false, sortable: 'custom', type: 'datetime', resizable: true, conf: {format: (val: any) => u.fmt.fmtDateTime(val)}},
  142. {label: '更新时间', prop: 'updateTime', query: false, sortable: 'custom', type: 'datetime', resizable: true, conf: {format: (val: any) => u.fmt.fmtDateTime(val)}},
  143. {
  144. label: '操作', prop: 'action', type: 'render', width: 180, align: 'center', fixed: 'right',
  145. render: (h: any, row: any) => {
  146. return (
  147. h('div', null, [
  148. proxy.$auth('washDevice.modify') ?
  149. h(ElButton, {
  150. type: 'warning',
  151. text: true,
  152. size: 'small',
  153. onClick: () => {
  154. handleRowClick('edit', row)
  155. }
  156. }, () => '编辑') : '',
  157. proxy.$auth('washDevice.modify') ?
  158. h(ElButton, {
  159. type: 'primary',
  160. text: true,
  161. size: 'small',
  162. onClick: () => {
  163. // handleRowClick('edit', row)
  164. }
  165. }, () => '结算') : '',
  166. proxy.$auth('washDevice.remove') ?
  167. h(ElButton, {
  168. type: 'danger',
  169. text: true,
  170. size: 'small',
  171. onClick: () => {
  172. handleRowDelete(row)
  173. }
  174. }, () => '删除') : '',
  175. ])
  176. )
  177. }
  178. }
  179. ],
  180. })
  181. // 监听双向绑定 modelValue 的变化
  182. // watch(
  183. // () => state.pageNum,
  184. // () => {
  185. //
  186. // }
  187. // );
  188. //生命周期钩子
  189. onBeforeMount(() => {
  190. let token = Session.get("token")
  191. let encodeToken = encodeURIComponent(token)
  192. let exportUrl = `poi/export?type=washDevice&X-Token=${encodeToken}`
  193. //导入导出参数配置
  194. state.importConfig = {
  195. auths: ['washDevice.add'],
  196. url: `poi/import?type=washDevice&X-Token=${encodeToken}`,
  197. template: `${exportUrl}&isTemplate=true`
  198. }
  199. state.exportConfig = {url: exportUrl,}
  200. })
  201. onMounted(() => {
  202. loadData();
  203. nextTick(() => {
  204. let bodyHeight = document.body.clientHeight;
  205. let queryHeight = queryRef.value.$el.clientHeight;
  206. state.tableData.height = bodyHeight - queryHeight - 220
  207. })
  208. mittBus.on("washDevice.refresh", () => {
  209. loadData();
  210. })
  211. });
  212. onBeforeUnmount(() => {
  213. mittBus.off("washDevice.refresh")
  214. })
  215. //region 方法区
  216. // 初始化表格数据
  217. const loadData = (refresh: boolean = false) => {
  218. if (refresh) {
  219. state.pageQuery.pageNum = 1;
  220. }
  221. state.tableData.loading = true;
  222. $body(`/washDevice/list`, {...state.formQuery, ...state.pageQuery}).then((res: any) => {
  223. let {list, total} = res;
  224. state.tableData.data = list;
  225. state.pageQuery.total = total;
  226. state.tableData.loading = false;
  227. }).catch(e => {
  228. //console.error(e)
  229. state.tableData.loading = false;
  230. })
  231. };
  232. // 配置详情页
  233. const handleRowConfigClick = (type: string, row: any) => {
  234. device_config_dialog_ref.value.open(type, row);
  235. }
  236. // 打开详情页弹窗
  237. const handleRowClick = (type: string, row: any) => {
  238. device_dialog_ref.value.open(type, row);
  239. };
  240. // 删除点击
  241. const handleRowDelete = (row: any) => {
  242. Msg.confirm(`此操作将永久删除:『${row.name}』,是否继续?`).then(() => {
  243. $get(`/washDevice/delete/${row.id}`).then(() => {
  244. Msg.message("删除成功", 'success')
  245. }).catch(() => {
  246. Msg.message("删除失败", 'error')
  247. })
  248. });
  249. };
  250. const handleBatchDeviceConfig = () => {
  251. device_config_dialog_ref.value.open(state.chooseDeviceList);
  252. }
  253. const handleChooseDeviceChange = (deviceList) => {
  254. console.log(deviceList)
  255. state.chooseDeviceList = deviceList.map(k=>k.id);
  256. }
  257. //endregion
  258. // 暴露变量
  259. // defineExpose({
  260. // loadData,
  261. // });
  262. </script>