diff --git a/src/api/sbgl/common/index.ts b/src/api/sbgl/common/index.ts index 103ead7..2f08a32 100644 --- a/src/api/sbgl/common/index.ts +++ b/src/api/sbgl/common/index.ts @@ -1,5 +1,26 @@ import request from '@/utils/request'; import { AxiosPromise } from 'axios'; +import { OssVO } from '@/api/system/oss/types'; + +/** 业务附件上传地址(登录即可,不依赖 system:oss:upload) */ +export const businessUploadUrl = import.meta.env.VITE_APP_BASE_API + '/sbgl/common/upload'; + +/** 业务附件地址解析(登录即可,不依赖 system:oss:query) */ +export function listBusinessOss(ids: string): AxiosPromise { + return request({ + url: '/sbgl/common/ossList', + method: 'get', + params: { ids } + }); +} + +/** 删除自己上传的业务附件 */ +export function deleteBusinessOss(ossId: string | number) { + return request({ + url: '/sbgl/common/oss/' + ossId, + method: 'delete' + }); +} /** 系统部门树(设备所属辖区 / 工单维护单位选择,登录即可) */ export function getCommonDeptTree(): AxiosPromise { diff --git a/src/api/sbgl/device/index.ts b/src/api/sbgl/device/index.ts index bd9d29d..e4678e8 100644 --- a/src/api/sbgl/device/index.ts +++ b/src/api/sbgl/device/index.ts @@ -55,6 +55,23 @@ export function delDevice(id: string | number | (string | number)[]) { }); } +// 回收站分页(已逻辑删除设备) +export function listRecycleDevice(query: DeviceQuery): AxiosPromise { + return request({ + url: '/sbgl/device/recycle/list', + method: 'get', + params: query + }); +} + +// 从回收站恢复设备 +export function restoreDevice(id: string | number) { + return request({ + url: '/sbgl/device/recycle/' + id, + method: 'put' + }); +} + // 下载导入模板(按设备类型动态生成) export function importTemplate(typeId: string | number) { return download('/sbgl/device/importTemplate', { typeId }, `设备导入模板_${typeId}.xlsx`); @@ -85,6 +102,29 @@ export function getLifecycle(id: string | number): AxiosPromise { }); } +// 单台设备二维码(返回 PNG Blob) +export function getDeviceQrcode(id: string | number): Promise { + return request({ + url: '/sbgl/device/qrcode/' + id, + method: 'get', + responseType: 'blob' + }) as unknown as Promise; +} + +// 按当前筛选条件批量导出设备二维码(ZIP) +export function exportDeviceQrcode(query: DeviceQuery) { + return download('/sbgl/device/qrcode/batch', query, `设备二维码_${new Date().getTime()}.zip`); +} + +// 扫码解析设备 +export function resolveDeviceQrcode(content: string): AxiosPromise { + return request({ + url: '/sbgl/device/qrcode/resolve', + method: 'post', + data: { content } + }); +} + // 某类型下启用的属性字段(大屏点位弹窗/详情展示用) export function listEnabledFields(typeId: string | number): AxiosPromise> { return request({ diff --git a/src/api/sbgl/device/types.ts b/src/api/sbgl/device/types.ts index 0f4f178..41b3fda 100644 --- a/src/api/sbgl/device/types.ts +++ b/src/api/sbgl/device/types.ts @@ -12,11 +12,14 @@ export interface DeviceVO { status: string; attrs?: Record; installDate?: string; + installLocation?: string; scrapDate?: string; scrapReason?: string; remark?: string; createTime?: string; updateTime?: string; + /** 列表二维码(Base64 Data URL,非数据库字段) */ + qrcode?: string; } export interface DeviceQuery extends PageQuery { @@ -38,6 +41,7 @@ export interface DeviceForm { status: string; attrs?: Record; installDate?: string; + installLocation?: string; scrapDate?: string; scrapReason?: string; remark?: string; diff --git a/src/api/sbgl/devicetype/index.ts b/src/api/sbgl/devicetype/index.ts index 3f7cce8..9a79243 100644 --- a/src/api/sbgl/devicetype/index.ts +++ b/src/api/sbgl/devicetype/index.ts @@ -69,6 +69,30 @@ export function listEnabledFields(typeId: string | number): AxiosPromise { + return request({ + url: '/sbgl/field/detail/' + typeId, + method: 'get' + }); +} + +// 字段回收站(已删除字段) +export function listDeletedFields(typeId: string | number): AxiosPromise { + return request({ + url: '/sbgl/field/recycle/' + typeId, + method: 'get' + }); +} + +// 从回收站恢复字段 +export function restoreField(id: string | number) { + return request({ + url: '/sbgl/field/restore/' + id, + method: 'put' + }); +} + // 批量保存字段配置(整体替换) export function batchSaveFields(typeId: string | number, data: DeviceFieldVO[]) { return request({ diff --git a/src/api/sbgl/devicetype/types.ts b/src/api/sbgl/devicetype/types.ts index ac5fb37..5a8a75b 100644 --- a/src/api/sbgl/devicetype/types.ts +++ b/src/api/sbgl/devicetype/types.ts @@ -27,12 +27,37 @@ export interface DeviceTypeForm { remark?: string; } +export type DeviceFieldType = + | 'text' + | 'textarea' + | 'number' + | 'integer' + | 'amount' + | 'percent' + | 'date' + | 'datetime' + | 'time' + | 'select' + | 'multiselect' + | 'radio' + | 'checkbox' + | 'switch' + | 'slider' + | 'rate' + | 'color' + | 'email' + | 'phone' + | 'url' + | 'ip' + | 'image' + | 'file'; + export interface DeviceFieldVO { id?: string | number; typeId: string | number; fieldKey: string; fieldLabel: string; - fieldType: 'text' | 'number' | 'date' | 'radio' | 'checkbox'; + fieldType: DeviceFieldType; options?: string; requiredFlag: number; sort: number; diff --git a/src/api/sbgl/roleScope/index.ts b/src/api/sbgl/roleScope/index.ts new file mode 100644 index 0000000..70cb1f6 --- /dev/null +++ b/src/api/sbgl/roleScope/index.ts @@ -0,0 +1,33 @@ +import request from '@/utils/request'; + +/** 设备资产模块标识 */ +export type RoleScopeModule = 'device' | 'order' | 'report' | string; + +export interface RoleScopeVO { + roleId: string | number; + module: RoleScopeModule; + /** 数据范围;为空表示沿用角色自身数据权限 */ + scopeType?: string; +} + +export interface RoleScopeForm { + module: RoleScopeModule; + scopeType?: string; +} + +/** 查询角色在各模块的数据范围 */ +export function getRoleScopes(roleId: string | number) { + return request({ + url: '/sbgl/roleScope/' + roleId, + method: 'get' + }); +} + +/** 保存角色模块数据范围 */ +export function saveRoleScopes(roleId: string | number, data: RoleScopeForm[]) { + return request({ + url: '/sbgl/roleScope/' + roleId, + method: 'put', + data + }); +} diff --git a/src/assets/sbgl-icons/barrier.svg b/src/assets/sbgl-icons/barrier.svg new file mode 100644 index 0000000..01fce60 --- /dev/null +++ b/src/assets/sbgl-icons/barrier.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/assets/sbgl-icons/led.svg b/src/assets/sbgl-icons/led.svg new file mode 100644 index 0000000..dc2dc67 --- /dev/null +++ b/src/assets/sbgl-icons/led.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/assets/sbgl-icons/other-power.svg b/src/assets/sbgl-icons/other-power.svg new file mode 100644 index 0000000..26d2380 --- /dev/null +++ b/src/assets/sbgl-icons/other-power.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/assets/sbgl-icons/other.svg b/src/assets/sbgl-icons/other.svg new file mode 100644 index 0000000..56825da --- /dev/null +++ b/src/assets/sbgl-icons/other.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/assets/sbgl-icons/radar.svg b/src/assets/sbgl-icons/radar.svg new file mode 100644 index 0000000..59e7227 --- /dev/null +++ b/src/assets/sbgl-icons/radar.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/assets/sbgl-icons/roadline.svg b/src/assets/sbgl-icons/roadline.svg new file mode 100644 index 0000000..5b197d2 --- /dev/null +++ b/src/assets/sbgl-icons/roadline.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/assets/sbgl-icons/signboard.svg b/src/assets/sbgl-icons/signboard.svg new file mode 100644 index 0000000..335e930 --- /dev/null +++ b/src/assets/sbgl-icons/signboard.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/assets/sbgl-icons/warning-post.svg b/src/assets/sbgl-icons/warning-post.svg new file mode 100644 index 0000000..2068a5b --- /dev/null +++ b/src/assets/sbgl-icons/warning-post.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/components/FileUpload/index.vue b/src/components/FileUpload/index.vue index 3cbb4b2..e1da915 100644 --- a/src/components/FileUpload/index.vue +++ b/src/components/FileUpload/index.vue @@ -46,7 +46,7 @@ + diff --git a/src/views/sbgl/device/detail.vue b/src/views/sbgl/device/detail.vue new file mode 100644 index 0000000..59ad21a --- /dev/null +++ b/src/views/sbgl/device/detail.vue @@ -0,0 +1,417 @@ + + + + + diff --git a/src/views/sbgl/device/index.vue b/src/views/sbgl/device/index.vue index 3e3bf97..7aeadbb 100644 --- a/src/views/sbgl/device/index.vue +++ b/src/views/sbgl/device/index.vue @@ -9,6 +9,11 @@ + + + @@ -38,13 +43,19 @@ 导出 + + 批量二维码 + + + 回收站 + - - + + @@ -53,16 +64,53 @@ - - + + - + + + + + @@ -76,8 +124,8 @@ - - + + @@ -125,19 +173,56 @@ 在地图上选取位置 + + + + + - - - - + + + + + - - + + - - - + + {{ opt }} + + + {{ opt }} + + + + + + + +
+ + % +
+ + + + + + +
@@ -165,7 +250,7 @@ + title="1. 选择设备类型并下载模板 → 2. 按模板填写 → 3. 上传导入;模板之外新增的列会自动创建为该类型的扩展字段。失败行会逐条给出原因。" /> @@ -196,37 +281,55 @@ - - - - + + + + + + + + + + + + + 搜索 + 重置 + + + + + + + + + + + + + + + + + + + diff --git a/src/views/sbgl/devicetype/fieldTypes.ts b/src/views/sbgl/devicetype/fieldTypes.ts new file mode 100644 index 0000000..6e14283 --- /dev/null +++ b/src/views/sbgl/devicetype/fieldTypes.ts @@ -0,0 +1,182 @@ +/** + * 设备扩展字段类型元数据 + * 字段配置抽屉、设备录入表单、设备列表动态列、大屏详情共用,保证类型定义一致 + */ +export interface FieldTypeMeta { + /** 类型值(存库) */ + value: string; + /** 类型名称 */ + label: string; + /** 是否需要配置选项 */ + options?: boolean; +} + +export interface FieldTypeGroup { + label: string; + types: FieldTypeMeta[]; +} + +/** 全部字段类型(按分组展示) */ +export const FIELD_TYPE_GROUPS: FieldTypeGroup[] = [ + { + label: '基础输入', + types: [ + { value: 'text', label: '单行文本' }, + { value: 'textarea', label: '多行文本' }, + { value: 'number', label: '数字' }, + { value: 'integer', label: '整数' }, + { value: 'amount', label: '金额(两位小数)' }, + { value: 'percent', label: '百分比(0-100)' } + ] + }, + { + label: '日期时间', + types: [ + { value: 'date', label: '日期' }, + { value: 'datetime', label: '日期时间' }, + { value: 'time', label: '时间' } + ] + }, + { + label: '选择项', + types: [ + { value: 'select', label: '下拉单选', options: true }, + { value: 'multiselect', label: '下拉多选', options: true }, + { value: 'radio', label: '单选按钮', options: true }, + { value: 'checkbox', label: '多选复选框', options: true } + ] + }, + { + label: '辅助控件', + types: [ + { value: 'switch', label: '开关(是/否)' }, + { value: 'slider', label: '滑块(0-100)' }, + { value: 'rate', label: '评分(0-5星)' }, + { value: 'color', label: '颜色' } + ] + }, + { + label: '格式校验', + types: [ + { value: 'email', label: '邮箱' }, + { value: 'phone', label: '手机号/座机' }, + { value: 'url', label: '链接地址' }, + { value: 'ip', label: 'IP地址' } + ] + }, + { + label: '媒体附件', + types: [ + { value: 'image', label: '图片上传' }, + { value: 'file', label: '附件上传' } + ] + } +]; + +export const FIELD_TYPES: FieldTypeMeta[] = FIELD_TYPE_GROUPS.flatMap((group) => group.types); + +export const FIELD_TYPE_MAP: Record = Object.fromEntries( + FIELD_TYPES.map((item) => [item.value, item] as const) +); + +/** 类型名称,未知类型原样返回 */ +export const fieldTypeLabel = (type?: string): string => FIELD_TYPE_MAP[type ?? '']?.label ?? (type || '-'); + +/** 是否需要配置选项 */ +export const needOptions = (type?: string): boolean => !!FIELD_TYPE_MAP[type ?? '']?.options; + +/** 解析选项配置:兼容 JSON 数组与逗号/顿号/分号分隔文本 */ +export const parseFieldOptions = (options?: string): string[] => { + if (!options) return []; + const text = options.trim(); + if (text.startsWith('[')) { + try { + const parsed = JSON.parse(text); + if (Array.isArray(parsed)) return [...new Set(parsed.map((v) => String(v).trim()).filter(Boolean))]; + } catch { + // 非合法 JSON,继续按分隔符解析 + } + } + return [...new Set(text.split(/[,,、;;]/).map((v) => v.trim()).filter(Boolean))]; +}; + +/** 开关值是否开启 */ +export const isSwitchOn = (value: any): boolean => + value === true || value === 1 || ['1', 'true', 'on', '是', '开', '启用'].includes(String(value).toLowerCase()); + +/** 多值字段转数组(兼容数组、JSON 数组字符串、分隔符字符串) */ +export const fieldValueArray = (value: any): string[] => { + if (value === null || value === undefined || value === '') return []; + if (Array.isArray(value)) return value.map((v) => String(v)).filter(Boolean); + if (typeof value === 'string') { + const text = value.trim(); + if (text.startsWith('[')) { + try { + const parsed = JSON.parse(text); + if (Array.isArray(parsed)) return parsed.map((v) => String(v)).filter(Boolean); + } catch { + // 非合法 JSON,继续按分隔符解析 + } + } + return text + .split(/[,,、;;]/) + .map((v) => v.trim()) + .filter(Boolean); + } + return [String(value)]; +}; + +/** 表单回显值归一化:多值转数组、数值转 number、开关转 1/0 */ +export const normalizeFieldValue = (type: string | undefined, value: any): any => { + if (value === null || value === undefined || value === '') { + return type === 'switch' ? 0 : undefined; + } + switch (type) { + case 'checkbox': + case 'multiselect': + return fieldValueArray(value); + case 'number': + case 'integer': + case 'amount': + case 'percent': + case 'slider': + case 'rate': { + const num = Number(value); + return Number.isNaN(num) ? value : num; + } + case 'switch': + return isSwitchOn(value) ? 1 : 0; + case 'time': + // el-time-picker 回显统一补全秒,兼容历史 HH:mm 数据 + return typeof value === 'string' && /^\d{2}:\d{2}$/.test(value) ? `${value}:00` : value; + default: + return value; + } +}; + +/** 列表/大屏纯文本展示 */ +export const formatFieldValue = (type: string | undefined, value: any): string => { + if (value === null || value === undefined || value === '') return '-'; + if (Array.isArray(value) && value.length === 0) return '-'; + switch (type) { + case 'switch': + return isSwitchOn(value) ? '是' : '否'; + case 'checkbox': + case 'multiselect': + return fieldValueArray(value).join('、') || '-'; + case 'percent': + return `${value}%`; + case 'rate': + return `${value} 星`; + case 'image': { + const count = fieldValueArray(value).length; + return count ? `图片(${count})` : '-'; + } + case 'file': { + const count = fieldValueArray(value).length; + return count ? `附件(${count})` : '-'; + } + default: + return String(value); + } +}; diff --git a/src/views/sbgl/devicetype/index.vue b/src/views/sbgl/devicetype/index.vue index 588d9e5..60be61a 100644 --- a/src/views/sbgl/devicetype/index.vue +++ b/src/views/sbgl/devicetype/index.vue @@ -66,8 +66,8 @@ - - + +
@@ -76,6 +76,23 @@
+ + +
+ 自定义图标 + × +
+
+ + + +
+ +
+
+
@@ -102,36 +119,29 @@ - + + title="只需填写显示标签,字段键会根据标签自动生成(标签重复时自动追加序号);保存后表单与列表列自动跟随变化,删除字段不影响历史数据。" /> - + - + - - - - + @@ -153,18 +163,39 @@ 添加字段 + 回收站 + + + + + + + + + + + + + + @@ -317,6 +441,7 @@ onMounted(() => { flex-wrap: wrap; .icon-item { + position: relative; width: 44px; height: 44px; display: flex; @@ -343,5 +468,39 @@ onMounted(() => { box-shadow: 0 0 0 1px #409eff inset; } } + + .icon-remove { + position: absolute; + top: -6px; + right: -6px; + width: 16px; + height: 16px; + line-height: 14px; + text-align: center; + border-radius: 50%; + background: #f56c6c; + color: #fff; + font-size: 12px; + cursor: pointer; + } + + .icon-uploader { + display: inline-flex; + + :deep(.el-upload) { + display: block; + } + } + + .icon-add { + border-style: dashed; + color: #909399; + font-size: 18px; + + &:hover { + border-color: #409eff; + color: #409eff; + } + } } diff --git a/src/views/sbgl/h5/order.vue b/src/views/sbgl/h5/order.vue index e77e145..129dd7b 100644 --- a/src/views/sbgl/h5/order.vue +++ b/src/views/sbgl/h5/order.vue @@ -61,6 +61,7 @@
{{ statusLabel(detail.status) }}
{{ detail.orderCode }}
+
{{ detail.title || '-' }}
{{ detail.deviceName }}
{{ typeLabel(detail.orderType) }}
{{ detail.description }}
@@ -167,9 +168,12 @@ - - - +
+ + + + 扫码 +
@@ -231,9 +235,8 @@ import { handleOrder, verifyOrder, closeOrder, urgeOrder, listOrderRecords } from '@/api/sbgl/workorder'; import { listTypeOptions } from '@/api/sbgl/devicetype'; -import { getDeviceOptions } from '@/api/sbgl/device'; -import { getCommonDeptTree, getDeptUsers } from '@/api/sbgl/common'; -import { listByIds } from '@/api/system/oss'; +import { getDeviceOptions, resolveDeviceQrcode } from '@/api/sbgl/device'; +import { getCommonDeptTree, getDeptUsers, listBusinessOss } from '@/api/sbgl/common'; const corpId = import.meta.env.VITE_DINGTALK_CORP_ID as string; @@ -436,7 +439,7 @@ const openDetail = async (o: any) => { try { const allIds = [...new Set(records.value.flatMap((rec: any) => (rec.images ? rec.images.split(',') : [])))].filter(Boolean).join(','); if (allIds) { - const ossRes = await listByIds(allIds); + const ossRes = await listBusinessOss(allIds); const urlMap: Record = {}; ((ossRes as any).data ?? []).forEach((it: any) => (urlMap[it.ossId] = it.url)); records.value.forEach((rec: any) => { @@ -555,7 +558,7 @@ const dingLocate = (): Promise<{ lng?: number; lat?: number }> => timeStamp: String(cfg.timeStamp ?? ''), nonceStr: cfg.nonceStr, signature: cfg.signature, - jsApiList: ['device.geolocation.get'] + jsApiList: ['device.geolocation.get', 'biz.util.scan'] }); dd.ready(() => { try { @@ -657,6 +660,50 @@ const loadDevices = async (name?: string) => { deviceOpts.value = (res as any).data ?? []; }; +/** 钉钉扫码选择设备:校验二维码后自动带出设备类型和设备 */ +const scanDevice = async () => { + if (!isDingTalk() || !dd.biz?.util?.scan) { + ElMessage.warning('请在钉钉客户端中使用扫码'); + return; + } + try { + const signUrl = window.location.href.split('#')[0]; + const res: any = await jsapiSign(signUrl); + const cfg = res?.data || {}; + dd.config({ + agentId: String(cfg.agentId ?? ''), + corpId, + timeStamp: String(cfg.timeStamp ?? ''), + nonceStr: cfg.nonceStr, + signature: cfg.signature, + jsApiList: ['biz.util.scan'] + }); + } catch { + ElMessage.error('扫码鉴权失败,请退出钉钉后重新进入'); + return; + } + dd.ready(() => { + dd.biz.util.scan({ + type: 'qrCode', + onSuccess: async (result: any) => { + const content = result?.text; + if (!content) return; + try { + const r: any = await resolveDeviceQrcode(content); + const device = r.data; + formTypeId.value = device.typeId; + await loadDevices(device.deviceName); + createForm.deviceId = device.id; + ElMessage.success(`已匹配设备:${device.deviceName}(${device.deviceCode})`); + } catch { + // 错误提示由请求拦截器统一处理 + } + }, + onFail: () => ElMessage.error('扫码失败或已取消') + }); + }); +}; + const openCreate = async () => { editId.value = ''; Object.assign(createForm, { orderType: 'bx', deviceId: '', title: '', description: '', images: '', deadline: '' }); @@ -787,6 +834,12 @@ onMounted(async () => {