index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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]">
  6. <el-card shadow="hover" :style="{ marginTop: '10px', height: '60px' }">
  7. <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="70px">
  8. <el-form-item label="设备标识" prop="identifier">
  9. <el-input v-model="queryParams.identifier" placeholder="请输入设备唯一标识" clearable @keyup.enter="handleQuery" />
  10. </el-form-item>
  11. <el-form-item label="加密字符" prop="encryptCode">
  12. <el-input v-model="queryParams.encryptCode" placeholder="请输入加密字符" clearable @keyup.enter="handleQuery" />
  13. </el-form-item>
  14. <el-form-item label="鉴权结果" prop="authResult">
  15. <el-select v-model="queryParams.authResult" placeholder="请选择鉴权结果" clearable @keyup.enter="handleQuery">
  16. <el-option v-for="dict in smsb_device_auth_result" :key="dict.value" :label="dict.label"
  17. :value="dict.value" />
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  22. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  23. </el-form-item>
  24. </el-form>
  25. </el-card>
  26. </div>
  27. </transition>
  28. <el-card shadow="never" style="height: calc(100% - 20px)">
  29. <div class="table-content">
  30. <el-table v-loading="loading" :data="deviceAuthList" @selection-change="handleSelectionChange">
  31. <el-table-column label="" align="left" prop="" width="10" />
  32. <el-table-column label="加密字符" align="left" prop="encryptCode" width="250" :show-overflow-tooltip="true" />
  33. <el-table-column label="解密字符" align="left" prop="decryptCode" width="250" :show-overflow-tooltip="true" />
  34. <el-table-column label="鉴权key" align="left" prop="authKey" width="150" :show-overflow-tooltip="true" />
  35. <el-table-column label="鉴权结果" align="center" prop="authResult" width="100">
  36. <template #default="scope">
  37. <dict-tag :options="smsb_device_auth_result" :value="scope.row.authResult" />
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="鉴权描述" align="left" prop="authRemark" :show-overflow-tooltip="true" width="120" />
  41. <el-table-column label="设备IP" align="center" prop="deviceIp" width="150" :show-overflow-tooltip="true" />
  42. <el-table-column label="设备名称" align="left" prop="deviceName" width="220" :show-overflow-tooltip="true" />
  43. <el-table-column label="设备标识" align="left" prop="identifier" width="220" :show-overflow-tooltip="true" />
  44. <el-table-column label="设备SN" align="left" prop="serialNumber" width="180" :show-overflow-tooltip="true" />
  45. <el-table-column label="设备MAC" align="left" prop="mac" width="150" />
  46. <el-table-column label="鉴权时间" align="center" prop="createTime" width="160" />
  47. <el-table-column label="操作" align="center" fixed="right" width="80" class-name="small-padding fixed-width">
  48. <template #default="scope">
  49. <el-tooltip content="删除" placement="top">
  50. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
  51. v-hasPermi="['device:deviceAuth:remove']">删除</el-button>
  52. </el-tooltip>
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. </div>
  57. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
  58. v-model:limit="queryParams.pageSize" @pagination="getList" />
  59. </el-card>
  60. <!-- 添加或修改设备鉴权对话框 -->
  61. <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
  62. <el-form ref="deviceAuthFormRef" :model="form" :rules="rules" label-width="80px">
  63. </el-form>
  64. <template #footer>
  65. <div class="dialog-footer">
  66. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  67. <el-button @click="cancel">取 消</el-button>
  68. </div>
  69. </template>
  70. </el-dialog>
  71. </div>
  72. </template>
  73. <script setup name="DeviceAuth" lang="ts">
  74. import { listDeviceAuth, getDeviceAuth, delDeviceAuth, addDeviceAuth, updateDeviceAuth } from '@/api/smsb/device/device_auth';
  75. import { DeviceAuthVO, DeviceAuthQuery, DeviceAuthForm } from '@/api/smsb/device/device_auth_type';
  76. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  77. const { smsb_device_auth_result } = toRefs<any>(proxy?.useDict('smsb_device_auth_result'));
  78. const deviceAuthList = ref<DeviceAuthVO[]>([]);
  79. const buttonLoading = ref(false);
  80. const loading = ref(true);
  81. const showSearch = ref(true);
  82. const ids = ref<Array<string | number>>([]);
  83. const single = ref(true);
  84. const multiple = ref(true);
  85. const total = ref(0);
  86. const queryFormRef = ref<ElFormInstance>();
  87. const deviceAuthFormRef = ref<ElFormInstance>();
  88. const dialog = reactive<DialogOption>({
  89. visible: false,
  90. title: ''
  91. });
  92. const initFormData: DeviceAuthForm = {
  93. }
  94. const data = reactive<PageData<DeviceAuthForm, DeviceAuthQuery>>({
  95. form: { ...initFormData },
  96. queryParams: {
  97. pageNum: 1,
  98. pageSize: 20,
  99. deviceIp: undefined,
  100. identifier: undefined,
  101. encryptCode: undefined,
  102. authResult: undefined,
  103. authKey: undefined,
  104. params: {
  105. }
  106. },
  107. rules: {
  108. }
  109. });
  110. const { queryParams, form, rules } = toRefs(data);
  111. /** 查询设备鉴权列表 */
  112. const getList = async () => {
  113. loading.value = true;
  114. const res = await listDeviceAuth(queryParams.value);
  115. deviceAuthList.value = res.rows;
  116. total.value = res.total;
  117. loading.value = false;
  118. }
  119. /** 取消按钮 */
  120. const cancel = () => {
  121. reset();
  122. dialog.visible = false;
  123. }
  124. /** 表单重置 */
  125. const reset = () => {
  126. form.value = { ...initFormData };
  127. deviceAuthFormRef.value?.resetFields();
  128. }
  129. /** 搜索按钮操作 */
  130. const handleQuery = () => {
  131. queryParams.value.pageNum = 1;
  132. getList();
  133. }
  134. /** 重置按钮操作 */
  135. const resetQuery = () => {
  136. queryFormRef.value?.resetFields();
  137. handleQuery();
  138. }
  139. /** 多选框选中数据 */
  140. const handleSelectionChange = (selection: DeviceAuthVO[]) => {
  141. ids.value = selection.map(item => item.id);
  142. single.value = selection.length != 1;
  143. multiple.value = !selection.length;
  144. }
  145. /** 新增按钮操作 */
  146. const handleAdd = () => {
  147. reset();
  148. dialog.visible = true;
  149. dialog.title = "添加设备鉴权";
  150. }
  151. /** 修改按钮操作 */
  152. const handleUpdate = async (row?: DeviceAuthVO) => {
  153. reset();
  154. const _id = row?.id || ids.value[0]
  155. const res = await getDeviceAuth(_id);
  156. Object.assign(form.value, res.data);
  157. dialog.visible = true;
  158. dialog.title = "修改设备鉴权";
  159. }
  160. /** 提交按钮 */
  161. const submitForm = () => {
  162. deviceAuthFormRef.value?.validate(async (valid: boolean) => {
  163. if (valid) {
  164. buttonLoading.value = true;
  165. if (form.value.id) {
  166. await updateDeviceAuth(form.value).finally(() => buttonLoading.value = false);
  167. } else {
  168. await addDeviceAuth(form.value).finally(() => buttonLoading.value = false);
  169. }
  170. proxy?.$modal.msgSuccess("操作成功");
  171. dialog.visible = false;
  172. await getList();
  173. }
  174. });
  175. }
  176. /** 删除按钮操作 */
  177. const handleDelete = async (row?: DeviceAuthVO) => {
  178. const _ids = row?.id || ids.value;
  179. await proxy?.$modal.confirm('是否确认删除已选择的数据项?').finally(() => loading.value = false);
  180. await delDeviceAuth(_ids);
  181. proxy?.$modal.msgSuccess("删除成功");
  182. await getList();
  183. }
  184. /** 导出按钮操作 */
  185. const handleExport = () => {
  186. proxy?.download('device/deviceAuth/export', {
  187. ...queryParams.value
  188. }, `deviceAuth_${new Date().getTime()}.xlsx`)
  189. }
  190. onMounted(() => {
  191. getList();
  192. });
  193. </script>