index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter"
  4. :leave-active-class="proxy?.animate.searchAnimate.leave">
  5. <div v-show="showSearch" class="mb-[10px]" :style="{ marginTop: '10px', height: '60px' }">
  6. <el-card shadow="hover">
  7. <el-form ref="queryFormRef" :model="queryParams" :inline="true" @submit.native.prevent>
  8. <el-form-item label="设备组" prop="name" label-width="60px">
  9. <el-input v-model="queryParams.name" placeholder="请输入设备组名称" clearable @keyup.enter="handleQuery"/>
  10. </el-form-item>
  11. <el-form-item>
  12. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  13. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  14. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['digital:deviceGroup:add']">
  15. 新增设备组
  16. </el-button>
  17. </el-form-item>
  18. </el-form>
  19. </el-card>
  20. </div>
  21. </transition>
  22. <el-card shadow="never">
  23. <!-- <template #header>
  24. <el-row :gutter="10" class="mb8">
  25. <el-col :span="1.5">
  26. </el-col>
  27. <el-col :span="1.5">
  28. <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()"
  29. v-hasPermi="['digital:deviceGroup:edit']">修改
  30. </el-button>
  31. </el-col>
  32. <el-col :span="1.5">
  33. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()"
  34. v-hasPermi="['digital:deviceGroup:remove']">删除
  35. </el-button>
  36. </el-col>
  37. <el-col :span="1.5">
  38. <el-button type="warning" plain icon="Download" @click="handleExport"
  39. v-hasPermi="['digital:deviceGroup:export']">导出
  40. </el-button>
  41. </el-col>
  42. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  43. </el-row>
  44. </template>-->
  45. <div class="table-content">
  46. <el-table v-loading="loading" :data="deviceGroupList" @selection-change="handleSelectionChange">
  47. <!-- <el-table-column type="selection" width="55" align="center"/>-->
  48. <el-table-column label="" align="left" prop="" width="15"/>
  49. <el-table-column label="ID" align="left" prop="id" v-if="true" width="250"/>
  50. <el-table-column label="设备组名称" align="left" prop="name" width="250"/>
  51. <el-table-column label="设备组容量" align="center" prop="capacity" width="250"/>
  52. <el-table-column label="备注" align="left" prop="remark" :show-overflow-tooltip="true"/>
  53. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
  54. <template #default="scope">
  55. <el-tooltip content="修改" placement="top">
  56. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
  57. v-hasPermi="['digital:deviceGroup:edit']"></el-button>
  58. </el-tooltip>
  59. <el-tooltip content="详情" placement="top">
  60. <el-button link type="primary" icon="View" @click="handleDevicesInfo(scope.row)"
  61. v-hasPermi="['digital:deviceGroupRel:query']"></el-button>
  62. </el-tooltip>
  63. <el-tooltip content="删除" placement="top">
  64. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
  65. v-hasPermi="['digital:deviceGroup:remove']"></el-button>
  66. </el-tooltip>
  67. </template>
  68. </el-table-column>
  69. </el-table>
  70. </div>
  71. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
  72. v-model:limit="queryParams.pageSize" @pagination="getList"/>
  73. </el-card>
  74. <!-- 添加或修改设备组信息对话框 -->
  75. <el-dialog :title="dialog.title" v-model="dialog.visible" width="1000px" append-to-body>
  76. <el-form ref="deviceGroupFormRef" :model="form" :rules="rules" label-width="50px">
  77. <el-row :gutter="20">
  78. <el-col :span="12">
  79. <el-form-item label="名称" prop="name">
  80. <el-input v-model="form.name" placeholder="请输入设备组名称"/>
  81. </el-form-item>
  82. </el-col>
  83. <el-col :span="12">
  84. <el-form-item label="容量" prop="capacity">
  85. <el-input v-model="form.capacity" placeholder="请输入设备组容量"/>
  86. </el-form-item>
  87. </el-col>
  88. </el-row>
  89. <el-form-item label="备注" prop="remark">
  90. <el-input v-model="form.remark" type="textarea" :rows="5" placeholder="请输入备注"/>
  91. </el-form-item>
  92. </el-form>
  93. <template #footer>
  94. <div class="dialog-footer">
  95. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  96. <el-button @click="cancel">取 消</el-button>
  97. </div>
  98. </template>
  99. </el-dialog>
  100. <!-- 查看设备组内的设备详情 -->
  101. <el-dialog :title="devicesLog.title" v-model="devicesLog.visible" width="1200px" append-to-body>
  102. <el-card shadow="never">
  103. <template #header>
  104. <el-row :gutter="10" class="mb8">
  105. <el-col :span="1.5">
  106. <el-button type="primary" plain icon="Plus" @click="handleAddDevice"
  107. v-hasPermi="['digital:deviceGroup:add']">新增
  108. </el-button>
  109. </el-col>
  110. </el-row>
  111. </template>
  112. <el-table v-loading="loading" :data="deviceList" @selection-change="handleDevicesSelectionChange">
  113. <!-- <el-table-column type="selection" width="55" align="center"/>-->
  114. <el-table-column label="设备名称" align="left" prop="deviceName" :show-overflow-tooltip="true"/>
  115. <el-table-column label="场景名称" align="center" prop="sceneName" width="200" :show-overflow-tooltip="true"/>
  116. <el-table-column label="场景序号" align="center" prop="sceneSort" width="150"/>
  117. <el-table-column label="备注" align="left" prop="remark" width="250" :show-overflow-tooltip="true"/>
  118. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
  119. <template #default="scope">
  120. <el-tooltip content="修改" placement="top">
  121. <el-button link type="primary" icon="Edit" @click="handleUpdateDevice(scope.row)"
  122. v-hasPermi="['digital:deviceGroup:edit']"></el-button>
  123. </el-tooltip>
  124. <el-tooltip content="删除" placement="top">
  125. <el-button link type="primary" icon="Delete" @click="handleDeleteDevice(scope.row)"
  126. v-hasPermi="['digital:deviceGroup:remove']"></el-button>
  127. </el-tooltip>
  128. </template>
  129. </el-table-column>
  130. </el-table>
  131. </el-card>
  132. <template #footer>
  133. <div class="dialog-footer">
  134. <el-button @click="cancel">取 消</el-button>
  135. </div>
  136. </template>
  137. </el-dialog>
  138. <el-dialog :title="addDeviceLog.title" v-model="addDeviceLog.visible" width="800px" append-to-body>
  139. <el-form ref="deviceGroupRelFormRef" :model="dataRel.form" :rules="dataRel.rules" label-width="80px">
  140. <el-form-item label="选择设备" prop="deviceIdentifier">
  141. <el-select v-model="dataRel.form.deviceIdentifier" placeholder="请选择设备" clearable
  142. @change="handleQueryRel">
  143. <el-option v-for="item in devices" :key="item.identifier" :value="item.identifier"
  144. :label="item.name"></el-option>
  145. </el-select>
  146. </el-form-item>
  147. <!-- <el-form-item label="设备组id" prop="deviceGroupId">-->
  148. <!-- <el-input v-model="dataRel.form.deviceName" placeholder="请输入设备组id" />-->
  149. <!-- </el-form-item>-->
  150. <el-row :gutter="20">
  151. <el-col :span="12">
  152. <el-form-item label="场景名称" prop="sceneName">
  153. <el-input v-model="dataRel.form.sceneName" placeholder="请输入场景名称"/>
  154. </el-form-item>
  155. </el-col>
  156. <el-col :span="12">
  157. <el-form-item label="场景序号" prop="sceneSort">
  158. <el-input-number :min="1" style="width: 280px" v-model="dataRel.form.sceneSort"
  159. placeholder="请输入场景序号"/>
  160. </el-form-item>
  161. </el-col>
  162. </el-row>
  163. <el-form-item label="备注" prop="remark">
  164. <el-input v-model="dataRel.form.remark" type="textarea" :rows="3" placeholder="请输入备注"/>
  165. </el-form-item>
  166. </el-form>
  167. <template #footer>
  168. <div class="dialog-footer">
  169. <el-button :loading="buttonLoading" type="primary" @click="submitFormRel">确 定</el-button>
  170. <el-button @click="cancelAddDevice">取 消</el-button>
  171. </div>
  172. </template>
  173. </el-dialog>
  174. </div>
  175. </template>
  176. <script setup name="DeviceGroup" lang="ts">
  177. import {
  178. listDeviceGroup,
  179. getDeviceGroup,
  180. delDeviceGroup,
  181. addDeviceGroup,
  182. updateDeviceGroup,
  183. } from '@/api/smsb/digital/deviceGroup';
  184. import {
  185. getGroupRelByGroupId,
  186. addDeviceGroupRel,
  187. delDeviceGroupRel,
  188. updateDeviceGroupRel
  189. } from '@/api/smsb/digital/deviceGroupRel';
  190. import {
  191. listDevice
  192. } from '@/api/smsb/device/device';
  193. import {DeviceGroupVO, DeviceGroupQuery, DeviceGroupForm} from '@/api/smsb/digital/deviceGroup/types';
  194. import {DeviceGroupRelVO, DeviceGroupRelForm, DeviceGroupRelQuery} from '@/api/smsb/digital/deviceGroupRel/types';
  195. import {DeviceQuery, DeviceVO, DeviceForm} from '@/api/smsb/device/device_type';
  196. const {proxy} = getCurrentInstance() as ComponentInternalInstance;
  197. const deviceGroupList = ref<DeviceGroupVO[]>([]);
  198. const deviceList = ref<DeviceGroupRelVO[]>([]);
  199. const devices = ref<DeviceVO[]>([]);
  200. const groupId = ref<string | number>();
  201. const buttonLoading = ref(false);
  202. const loading = ref(true);
  203. const showSearch = ref(true);
  204. const ids = ref<Array<string | number>>([]);
  205. const single = ref(true);
  206. const multiple = ref(true);
  207. const total = ref(0);
  208. const queryFormRef = ref<ElFormInstance>();
  209. const deviceGroupFormRef = ref<ElFormInstance>();
  210. const deviceGroupRelFormRef = ref<ElFormInstance>();
  211. const dialog = reactive<DialogOption>({
  212. visible: false,
  213. title: ''
  214. });
  215. const devicesLog = reactive<DialogOption>({
  216. visible: false,
  217. title: ''
  218. });
  219. const addDeviceLog = reactive<DialogOption>({
  220. visible: false,
  221. title: ''
  222. });
  223. const initFormData: DeviceGroupForm = {
  224. id: undefined,
  225. name: undefined,
  226. capacity: undefined,
  227. remark: undefined,
  228. }
  229. const data = reactive<PageData<DeviceGroupForm, DeviceGroupQuery>>({
  230. form: {...initFormData},
  231. queryParams: {
  232. pageNum: 1,
  233. pageSize: 10,
  234. name: undefined,
  235. capacity: undefined,
  236. params: {}
  237. },
  238. rules: {
  239. id: [
  240. {required: true, message: "设备组id不能为空", trigger: "blur"}
  241. ],
  242. name: [
  243. {required: true, message: "设备组名称不能为空", trigger: "blur"}
  244. ],
  245. capacity: [
  246. {required: true, message: "设备组容量不能为空", trigger: "blur"}
  247. ],
  248. remark: [
  249. {required: false, message: "备注不能为空", trigger: "blur"}
  250. ],
  251. }
  252. });
  253. const initFormDataRel: DeviceGroupRelForm = {
  254. id: undefined,
  255. deviceGroupId: undefined,
  256. deviceIdentifier: undefined,
  257. deviceName: undefined,
  258. sceneSort: undefined,
  259. sceneName: undefined,
  260. remark: undefined,
  261. }
  262. const dataRel = reactive<PageData<DeviceGroupRelForm, DeviceQuery>>({
  263. form: {...initFormDataRel},
  264. queryParams: {
  265. pageNum: 1,
  266. pageSize: 10,
  267. identifier: undefined,
  268. name: undefined,
  269. mac: undefined,
  270. onlineStatus: undefined,
  271. params: {}
  272. },
  273. rules: {
  274. id: [
  275. {required: false, message: "对应表id不能为空", trigger: "blur"}
  276. ],
  277. deviceGroupId: [
  278. {required: false, message: "设备组id不能为空", trigger: "blur"}
  279. ],
  280. deviceIdentifier: [
  281. {required: true, message: "设备标识不能为空", trigger: "blur"}
  282. ],
  283. deviceName: [
  284. {required: false, message: "设备标名称不能为空", trigger: "blur"}
  285. ],
  286. sceneSort: [
  287. {required: true, message: "场景序号不能为空", trigger: "blur"}
  288. ],
  289. sceneName: [
  290. {required: true, message: "场景名称不能为空", trigger: "blur"}
  291. ],
  292. remark: [
  293. {required: false, message: "备注不能为空", trigger: "blur"}
  294. ],
  295. }
  296. });
  297. const {queryParams, form, rules} = toRefs(data);
  298. // const { queryParams, form, rules } = toRefs(dataRe);
  299. /** 查询设备组信息列表 */
  300. const getList = async () => {
  301. loading.value = true;
  302. const res = await listDeviceGroup(queryParams.value);
  303. deviceGroupList.value = res.rows;
  304. total.value = res.total;
  305. loading.value = false;
  306. }
  307. const getListRel = async () => {
  308. loading.value = true;
  309. const res = await listDevice(dataRel.queryParams);
  310. devices.value = res.rows;
  311. total.value = res.total;
  312. loading.value = false;
  313. }
  314. /** 设备组详情 */
  315. const handleDevicesInfo = async (row?: DeviceGroupVO) => {
  316. loading.value = true;
  317. const _id = row?.id || ids.value[0]
  318. groupId.value = row.id;
  319. const res = await getGroupRelByGroupId(_id);
  320. deviceList.value = res.data;
  321. devicesLog.visible = true;
  322. devicesLog.title = "设备组详情";
  323. loading.value = false;
  324. }
  325. /** 新增按钮操作 */
  326. const handleAddDevice = () => {
  327. reset();
  328. handleQueryRel()
  329. addDeviceLog.visible = true;
  330. addDeviceLog.title = "添加设备";
  331. }
  332. /** 修改设备信息 */
  333. const handleUpdateDevice = async (row?: DeviceGroupRelVO) => {
  334. reset();
  335. // const _id = row?.id || ids.value[0]
  336. // const res = await getDeviceGroup(_id);
  337. Object.assign(dataRel.form, row);
  338. handleQueryRel();
  339. addDeviceLog.visible = true;
  340. addDeviceLog.title = "修改设备信息";
  341. }
  342. /** 取消按钮 */
  343. const cancel = () => {
  344. reset();
  345. dialog.visible = false;
  346. devicesLog.visible = false;
  347. }
  348. const cancelAddDevice = () => {
  349. reset();
  350. addDeviceLog.visible = false;
  351. }
  352. /** 表单重置 */
  353. const reset = () => {
  354. form.value = {...initFormData};
  355. deviceGroupFormRef.value?.resetFields();
  356. }
  357. /** 搜索按钮操作 */
  358. const handleQuery = () => {
  359. queryParams.value.pageNum = 1;
  360. getList();
  361. };
  362. /** 搜索按钮操作 */
  363. const handleQueryRel = () => {
  364. dataRel.queryParams.pageNum = 1;
  365. getListRel();
  366. }
  367. /** 重置按钮操作 */
  368. const resetQuery = () => {
  369. queryFormRef.value?.resetFields();
  370. handleQuery();
  371. }
  372. /** 多选框选中数据 */
  373. const handleSelectionChange = (selection: DeviceGroupVO[]) => {
  374. ids.value = selection.map(item => item.id);
  375. single.value = selection.length != 1;
  376. multiple.value = !selection.length;
  377. }
  378. /** 多选框选中数据 */
  379. const handleDevicesSelectionChange = (selection: DeviceGroupRelVO[]) => {
  380. ids.value = selection.map(item => item.id);
  381. single.value = selection.length != 1;
  382. multiple.value = !selection.length;
  383. }
  384. /** 新增按钮操作 */
  385. const handleAdd = () => {
  386. reset();
  387. dialog.visible = true;
  388. dialog.title = "添加设备组信息";
  389. }
  390. /** 修改按钮操作 */
  391. const handleUpdate = async (row?: DeviceGroupVO) => {
  392. reset();
  393. const _id = row?.id || ids.value[0]
  394. const res = await getDeviceGroup(_id);
  395. Object.assign(form.value, res.data);
  396. dialog.visible = true;
  397. dialog.title = "修改设备组信息";
  398. }
  399. const submitFormRel = () => {
  400. // console.log("groupId:" + groupId.value);
  401. // console.log("dataRel:" + dataRel.form.deviceIdentifier);
  402. dataRel.form.deviceGroupId = groupId.value;
  403. deviceGroupRelFormRef.value?.validate(async (valid: boolean) => {
  404. if (valid) {
  405. buttonLoading.value = true;
  406. if (dataRel.form.id) {
  407. await updateDeviceGroupRel(dataRel.form).finally(() => buttonLoading.value = false);
  408. } else {
  409. await addDeviceGroupRel(dataRel.form).finally(() => buttonLoading.value = false);
  410. }
  411. proxy?.$modal.msgSuccess("操作成功");
  412. addDeviceLog.visible = false;
  413. const res = await getGroupRelByGroupId(groupId.value);
  414. deviceList.value = res.data;
  415. // devicesLog.visible = true;
  416. // devicesLog.title = "设备组详情";
  417. }
  418. });
  419. }
  420. /** 提交按钮 */
  421. const submitForm = () => {
  422. deviceGroupFormRef.value?.validate(async (valid: boolean) => {
  423. if (valid) {
  424. buttonLoading.value = true;
  425. if (form.value.id) {
  426. await updateDeviceGroup(form.value).finally(() => buttonLoading.value = false);
  427. } else {
  428. await addDeviceGroup(form.value).finally(() => buttonLoading.value = false);
  429. }
  430. proxy?.$modal.msgSuccess("操作成功");
  431. dialog.visible = false;
  432. await getList();
  433. }
  434. });
  435. }
  436. /** 删除按钮操作 */
  437. const handleDelete = async (row?: DeviceGroupVO) => {
  438. const _ids = row?.id || ids.value;
  439. await proxy?.$modal.confirm('是否确认删除设备组信息编号为"' + _ids + '"的数据项?').finally(() => loading.value = false);
  440. await delDeviceGroup(_ids);
  441. proxy?.$modal.msgSuccess("删除成功");
  442. await getList();
  443. }
  444. const handleDeleteDevice = async (row?: DeviceGroupRelVO) => {
  445. const _ids = row?.id || ids.value;
  446. await proxy?.$modal.confirm('是否确认删除设备信息编号为"' + _ids + '"的数据项?').finally(() => loading.value = false);
  447. await delDeviceGroupRel(_ids);
  448. proxy?.$modal.msgSuccess("删除成功");
  449. const res = await getGroupRelByGroupId(groupId.value);
  450. deviceList.value = res.data;
  451. }
  452. /** 导出按钮操作 */
  453. const handleExport = () => {
  454. proxy?.download('digital/deviceGroup/export', {
  455. ...queryParams.value
  456. }, `deviceGroup_${new Date().getTime()}.xlsx`)
  457. }
  458. onMounted(() => {
  459. getList();
  460. });
  461. </script>