diff --git a/.env.development b/.env.development index 4fbe76a..6e0da17 100644 --- a/.env.development +++ b/.env.development @@ -5,8 +5,8 @@ VUE_APP_TITLE = 共享空间 ENV = 'development' # 共享空间/开发环境 -VUE_APP_BASE_API = 'https://testcha.chuangtewl.com/prod-api' -# VUE_APP_BASE_API = 'http://localhost:8089' +# VUE_APP_BASE_API = 'https://testcha.chuangtewl.com/prod-api' +VUE_APP_BASE_API = 'http://192.168.2.43:8089' # 路由懒加载 VUE_CLI_BABEL_TRANSPILE_MODULES = true diff --git a/src/api/system/device.js b/src/api/system/device.js index 2dc7388..3df6f16 100644 --- a/src/api/system/device.js +++ b/src/api/system/device.js @@ -140,3 +140,11 @@ export function getDeviceBySn(sn){ }) } +// 绑定设备设施 +export function bindDeviceFacility(data){ + return request({ + url: '/system/device/bindDeviceFacility/'+data.equipmentId+'/'+data.deviceId, + method: 'post', + // data: data + }) +} \ No newline at end of file diff --git a/src/router/index.js b/src/router/index.js index 4b54d13..3d541e1 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -162,6 +162,20 @@ export const dynamicRoutes = [ } ] }, + { + path: '/system/roomDetail', + component: Layout, + hidden: true, + permissions: ['system:room:list'], + children: [ + { + path: 'detail/:roomId(\\d+)', + component: () => import('@/views/system/room/room_detail'), + name: 'RoomDetail', + meta: { title: '房间详情', activeMenu: '/system/room' } + } + ] + }, { path: '/system/device/sn', component: Layout, @@ -245,7 +259,8 @@ export const dynamicRoutes = [ meta: { title: '用户详情', activeMenu: '/user/user' } } ] - } + }, + ] // 防止连续点击多次路由报错 diff --git a/src/views/system/commandLog/index.vue b/src/views/system/commandLog/index.vue index 7aff973..a5a17a0 100644 --- a/src/views/system/commandLog/index.vue +++ b/src/views/system/commandLog/index.vue @@ -9,7 +9,7 @@ @keyup.enter.native="handleQuery" /> - + - + 设备信息
- + 修改 @@ -37,7 +24,8 @@

扫描二维码进行设备绑定

- 下载二维码 + 下载二维码 @@ -86,10 +74,7 @@ 型号功能: @@ -331,200 +377,356 @@ import { handleUnlocking, reboot, refreshDevice, - delDevice + delDevice, + bindDeviceFacility, + bindDeviceUser } from '@/api/system/device' +import { listUser } from "@/api/user/user" import { listData } from '@/api/system/dict/data' +import { listEquipment } from "@/api/system/equipment" import QrCode from '@/components/QrCode/index.vue' import QRCode from 'qrcode' - +import Role from '@/views/system/rule/index.vue' +import Log from '@/views/system/commandLog/index.vue' export default { - name: 'DeviceDetail', - components: { QrCode }, + name: "DeviceDetail", + components: { + QrCode,Role,Log + }, + dicts: ['ss_equipment_type', 'ss_equipment_status', 'ss_user_type'], data() { return { - deviceData: {}, - isEditing: false, // 是否处于编辑状态 + // 设备数据 + deviceData: { + modelTags: [] // 初始化为空数组 + }, + loading: false, + isEditing: false, + + // 编辑表单数据 editForm: { - deviceId: '', - deviceName: '', + deviceId: undefined, mac: '', mac2: '', sn: '', model: '', productId: '', - modelTags: [], + deviceName: '', + roomName: '', storeName: '', - serviceRate: '', userName: '', remark: '', - roomName: '' + modelTags: [], + serviceRate: undefined }, - activeTab: 'packages', + + // 设施相关数据 + bindFacilityDialogVisible: false, + facilityTableLoading: false, + facilityList: [], + facilityTotal: 0, + facilityQueryParams: { + pageNum: 1, + pageSize: 10 + }, + facilityOptions: [], + modelTagOptions: [], + + // 用户相关数据 + bindUserDialogVisible: false, + userTableLoading: false, + userList: [], + userTotal: 0, + userQueryParams: { + pageNum: 1, + pageSize: 10, + userName: undefined, + phonenumber: undefined, + status: undefined, + userType: '01' + }, + + // 标签页相关 + activeTab: 'logs', searchForm: { userName: '', userPhone: '', packageName: '', chargeMode: '', chargeType: '' - }, - queryParams: { - pageNum: 1, - pageSize: 10, - dictType: 'sm_model_tag', - dictLabel: undefined, - status: undefined - }, - facilityOptions: [], - modelTagOptions: [], - loading: true + } } }, computed: { + qrCodeText() { + return this.deviceData.sn || '' + }, modelTags() { return this.deviceData.modelTags ? this.deviceData.modelTags.map(tag => { const modelTag = this.modelTagOptions.find(option => option.dictValue === tag); + + return modelTag ? modelTag.dictLabel : tag; }) : []; }, - serviceModeText() { - switch (this.deviceData.serviceMode) { - case "1": return "直营模式"; - case "2": return "代理模式"; - default: return "--"; - } - }, facilityTag() { - const facility = this.facilityOptions.find(option => option.dictValue === this.deviceData.serviceRate); - return facility ? facility.dictLabel : '--'; - }, - qrCodeText() { - return this.deviceData.qrText || '无二维码信息'; + return this.deviceData.facilityName || '--' } }, created() { - const deviceId = this.$route.params.deviceId; + const deviceId = this.$route.params.deviceId + + this.fetchFacilityOptions() + this.fetchModelTagOptions() if (deviceId) { - this.fetchDeviceData(deviceId); + this.fetchDeviceData(deviceId) } - this.fetchFacilityOptions(); - this.fetchModelTagOptions(); }, methods: { - // 切换编辑状态 - toggleEdit() { - this.isEditing = true; - // 复制当前数据到编辑表单 - this.editForm = { - deviceId: this.deviceData.deviceId, - deviceName: this.deviceData.deviceName, - mac: this.deviceData.mac, - mac2: this.deviceData.mac2, - sn: this.deviceData.sn, - model: this.deviceData.model, - productId: this.deviceData.productId, - modelTags: this.deviceData.modelTags || [], - storeName: this.deviceData.storeName, - serviceRate: this.deviceData.serviceRate, - userName: this.deviceData.userName, - remark: this.deviceData.remark, - roomName: this.deviceData.monthFee - }; + toUserDetail(){ + if (this.deviceData.userId) { + this.$router.push(`/user/detail/${this.deviceData.userId}`); + } }, - - // 保存编辑 - handleSave() { - updateDevice(this.editForm).then(() => { - this.$message.success("设备信息已更新"); - this.isEditing = false; - // 重新获取设备数据 - this.fetchDeviceData(this.editForm.deviceId); - }).catch(() => { - this.$message.error("更新设备信息失败"); - }); - }, - - // 取消编辑 - handleCancel() { - this.isEditing = false; - this.editForm = {}; - }, - fetchDeviceData(deviceId) { + this.loading = true getDevice(deviceId).then(response => { - this.deviceData = response.data; - this.loading = false; + if (response.data) { + // 确保modelTags是数组 + this.deviceData = { + ...response.data, + modelTags: Array.isArray(response.data.modelTags) + ? response.data.modelTags + : (response.data.modelTags ? response.data.modelTags.split(',') : []) + } + } + this.loading = false }).catch(error => { - this.$message.error("获取设备详情失败"); - this.loading = false; - }); + this.$message.error("获取设备详情失败") + this.loading = false + }) + }, + formatFeeRules(feeRuleVOS) { + if (!feeRuleVOS || !feeRuleVOS.length) { + return '-'; + } + return feeRuleVOS.map(rule => rule.explain).join(','); }, - fetchFacilityOptions() { - listData({ pageNum: 1, pageSize: 10, dictType: 'ss_equipment_type' }).then(response => { - this.facilityOptions = response.rows; - }).catch(error => { - this.$message.error("获取绑定设施数据失败"); - }); + listData({ dictType: 'ss_equipment_type' }).then(response => { + this.facilityOptions = response.rows || [] + }).catch(() => { + this.$message.error("获取绑定设施数据失败") + }) }, fetchModelTagOptions() { - listData(this.queryParams).then(response => { - this.modelTagOptions = response.rows; - }).catch(error => { - this.$message.error("获取modelTags数据失败"); + listData({ dictType: 'sm_model_tag' }).then(response => { + this.modelTagOptions = response.rows || [] + console.log(this.modelTagOptions, 'this.modelTagOptions'); + }).catch(() => { + this.$message.error("获取型号功能数据失败") + }) + }, + getFacilityList() { + this.facilityTableLoading = true; + // 修改查询参数 + const queryParams = { + pageNum: this.facilityQueryParams.pageNum, + pageSize: this.facilityQueryParams.pageSize, + name: undefined, + type: undefined, + status: undefined + }; + + listEquipment(queryParams).then(response => { + this.facilityList = response.rows; + this.facilityTotal = response.total; + this.facilityTableLoading = false; + }).catch(() => { + this.$message.error("获取设施列表失败"); + this.facilityTableLoading = false; }); }, + toggleEdit() { + this.isEditing = true + this.editForm = { + ...this.deviceData, + modelTags: Array.isArray(this.deviceData.modelTags) + ? [...this.deviceData.modelTags] + : [] + } + }, + + handleSave() { + updateDevice(this.editForm).then(() => { + this.$message.success("保存成功") + this.isEditing = false + this.fetchDeviceData(this.deviceData.deviceId) + }).catch(() => { + this.$message.error("保存失败") + }) + }, + + handleCancel() { + this.isEditing = false + this.editForm = {} + }, downloadQRCode() { - const qrText = this.qrCodeText; + const qrText = this.qrCodeText + if (!qrText) { + this.$message.warning("没有可用的设备SN码") + return + } QRCode.toDataURL(qrText, { width: 150, height: 150 }, (err, url) => { if (err) { - this.$message.error("生成二维码失败"); - return; + this.$message.error("生成二维码失败") + return } - const link = document.createElement('a'); - link.href = url; - link.download = `${this.deviceData.sn || 'unknown'}.png`; - link.click(); - }); + const link = document.createElement('a') + link.href = url + link.download = `${this.deviceData.sn || 'device'}.png` + link.click() + }) }, handleUnlocking(row) { handleUnlocking(row.deviceId).then(() => { - this.$message.success("设备已解锁"); - }); + this.$message.success("设备已解锁") + }) }, handleLock(row) { handleLock(row.deviceId).then(() => { - this.$message.success("设备已锁定"); - }); + this.$message.success("设备已锁定") + }) }, reboot(row) { reboot(row.deviceId).then(() => { - this.$message.success("设备已重启"); - }); + this.$message.success("设备已重启") + }) }, refresh(row) { refreshDevice(row.deviceId).then(() => { - this.$message.success("设备已更新"); - }); + this.$message.success("设备已更新") + }) }, handleDelete(row) { - delDevice(row.deviceId).then(() => { - this.$message.success("设备已删除"); - }); + this.$modal.confirm('是否确认删除该设备?').then(() => { + return delDevice(row.deviceId) + }).then(() => { + this.$message.success("设备已删除") + this.$router.push('/system/device') + }).catch(() => { }) + }, + + openBindFacilityDialog() { + this.bindFacilityDialogVisible = true + this.getFacilityList() + }, + + getFacilityList() { + this.facilityTableLoading = true + listEquipment(this.facilityQueryParams).then(response => { + this.facilityList = response.rows || [] + this.facilityTotal = response.total || 0 + this.facilityTableLoading = false + }) + }, + + handleBindFacility(row) { + this.$modal.confirm('确认要将该设备绑定到设施"' + row.name + '"吗?').then(() => { + return bindDeviceFacility({ + deviceId: this.deviceData.deviceId, + equipmentId: row.equipmentId + }) + }).then(() => { + this.$modal.msgSuccess("绑定成功") + this.bindFacilityDialogVisible = false + this.fetchDeviceData(this.deviceData.deviceId) + }).catch(() => { }) + }, + + handleOnline(row) { + const status = row.status === '8' ? '0' : '8' + const statusText = status === '8' ? '禁用' : '启用' + + this.$modal.confirm('确认要' + statusText + '该设备吗?').then(() => { + return updateDevice({ + deviceId: row.deviceId, + status: status + }) + }).then(() => { + this.$modal.msgSuccess(statusText + "成功") + this.fetchDeviceData(row.deviceId) + }).catch(() => { }) + }, + + openBindUserDialog() { + this.bindUserDialogVisible = true + this.getUserList() + }, + + getUserList() { + this.userTableLoading = true + listUser(this.userQueryParams).then(response => { + this.userList = response.rows || [] + this.userTotal = response.total || 0 + this.userTableLoading = false + }) + }, + // 搜索按钮操作 + handleUserQuery() { + this.userQueryParams.pageNum = 1; + this.getUserList(); + }, + + // 重置按钮操作 + resetUserQuery() { + this.$refs["queryForm"].resetFields(); + this.userQueryParams = { + pageNum: 1, + pageSize: 10, + userName: undefined, + phonenumber: undefined, + status: undefined, + userType: '01' + }; + this.handleUserQuery(); + }, + handleBindUser(row) { + this.$modal.confirm('确认要将该设备绑定到商户"' + row.userName + '"吗?').then(() => { + return bindDeviceUser({ + deviceId: this.deviceData.deviceId, + userId: row.userId + }) + }).then(() => { + this.$modal.msgSuccess("绑定成功") + this.bindUserDialogVisible = false + this.fetchDeviceData(this.deviceData.deviceId) + }).catch(() => { }) } } } + + + \ No newline at end of file diff --git a/src/views/user/user/index.vue b/src/views/user/user/index.vue index eb1293e..00f7af1 100644 --- a/src/views/user/user/index.vue +++ b/src/views/user/user/index.vue @@ -351,6 +351,7 @@ export default { name: "User", components: {UserConfigDialog }, dicts: ['sys_normal_disable', 'sys_user_sex','et_user_is_authentication','ss_user_type'], + props: ['storeId'], data() { return { showConfigDialog: false, @@ -481,6 +482,7 @@ export default { }, /** 查询用户列表 */ getList() { + this.queryParams.storeId = this.storeId; this.loading = true; listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => { this.userList = response.rows;