-f 项目优化
@ -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<OssVO[]> {
|
||||
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<any[]> {
|
||||
|
||||
@ -55,6 +55,23 @@ export function delDevice(id: string | number | (string | number)[]) {
|
||||
});
|
||||
}
|
||||
|
||||
// 回收站分页(已逻辑删除设备)
|
||||
export function listRecycleDevice(query: DeviceQuery): AxiosPromise<DeviceVO[]> {
|
||||
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<LifecycleVO> {
|
||||
});
|
||||
}
|
||||
|
||||
// 单台设备二维码(返回 PNG Blob)
|
||||
export function getDeviceQrcode(id: string | number): Promise<Blob> {
|
||||
return request({
|
||||
url: '/sbgl/device/qrcode/' + id,
|
||||
method: 'get',
|
||||
responseType: 'blob'
|
||||
}) as unknown as Promise<Blob>;
|
||||
}
|
||||
|
||||
// 按当前筛选条件批量导出设备二维码(ZIP)
|
||||
export function exportDeviceQrcode(query: DeviceQuery) {
|
||||
return download('/sbgl/device/qrcode/batch', query, `设备二维码_${new Date().getTime()}.zip`);
|
||||
}
|
||||
|
||||
// 扫码解析设备
|
||||
export function resolveDeviceQrcode(content: string): AxiosPromise<DeviceVO> {
|
||||
return request({
|
||||
url: '/sbgl/device/qrcode/resolve',
|
||||
method: 'post',
|
||||
data: { content }
|
||||
});
|
||||
}
|
||||
|
||||
// 某类型下启用的属性字段(大屏点位弹窗/详情展示用)
|
||||
export function listEnabledFields(typeId: string | number): AxiosPromise<Array<{ fieldKey: string; fieldLabel: string; fieldType: string }>> {
|
||||
return request({
|
||||
|
||||
@ -12,11 +12,14 @@ export interface DeviceVO {
|
||||
status: string;
|
||||
attrs?: Record<string, any>;
|
||||
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<string, any>;
|
||||
installDate?: string;
|
||||
installLocation?: string;
|
||||
scrapDate?: string;
|
||||
scrapReason?: string;
|
||||
remark?: string;
|
||||
|
||||
@ -69,6 +69,30 @@ export function listEnabledFields(typeId: string | number): AxiosPromise<DeviceF
|
||||
});
|
||||
}
|
||||
|
||||
// 设备详情展示用:全部有效字段(含停用)
|
||||
export function listDetailFields(typeId: string | number): AxiosPromise<DeviceFieldVO[]> {
|
||||
return request({
|
||||
url: '/sbgl/field/detail/' + typeId,
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
||||
// 字段回收站(已删除字段)
|
||||
export function listDeletedFields(typeId: string | number): AxiosPromise<DeviceFieldVO[]> {
|
||||
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({
|
||||
|
||||
@ -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;
|
||||
|
||||
33
src/api/sbgl/roleScope/index.ts
Normal file
@ -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
|
||||
});
|
||||
}
|
||||
8
src/assets/sbgl-icons/barrier.svg
Normal file
@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
|
||||
<circle cx="100" cy="100" r="92" fill="#4a5a6a"/>
|
||||
<rect x="34" y="64" width="132" height="12" rx="6" fill="#ffffff"/>
|
||||
<rect x="34" y="110" width="132" height="12" rx="6" fill="#ffffff"/>
|
||||
<rect x="46" y="48" width="14" height="98" rx="7" fill="#ffffff"/>
|
||||
<rect x="93" y="48" width="14" height="98" rx="7" fill="#ffffff"/>
|
||||
<rect x="140" y="48" width="14" height="98" rx="7" fill="#ffffff"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 471 B |
10
src/assets/sbgl-icons/led.svg
Normal file
@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
|
||||
<circle cx="100" cy="100" r="92" fill="#1d6fd0"/>
|
||||
<rect x="40" y="44" width="120" height="82" rx="10" fill="#ffffff"/>
|
||||
<rect x="50" y="58" width="52" height="10" rx="5" fill="#ffb300"/>
|
||||
<rect x="50" y="76" width="66" height="10" rx="5" fill="#ffb300"/>
|
||||
<rect x="50" y="94" width="38" height="10" rx="5" fill="#ffb300"/>
|
||||
<path d="M120 66 L152 88 L120 110 Z" fill="#1d6fd0"/>
|
||||
<rect x="92" y="126" width="16" height="32" rx="4" fill="#ffffff"/>
|
||||
<rect x="68" y="154" width="64" height="12" rx="6" fill="#ffffff"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 596 B |
4
src/assets/sbgl-icons/other-power.svg
Normal file
@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
|
||||
<circle cx="100" cy="100" r="92" fill="#f5a623"/>
|
||||
<path d="M114 30 L64 108 H94 L82 170 L138 86 H106 Z" fill="#ffffff"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 194 B |
7
src/assets/sbgl-icons/other.svg
Normal file
@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
|
||||
<circle cx="100" cy="100" r="92" fill="#7a8699"/>
|
||||
<rect x="54" y="62" width="92" height="76" rx="16" fill="none" stroke="#ffffff" stroke-width="9"/>
|
||||
<circle cx="78" cy="100" r="7" fill="#ffffff"/>
|
||||
<circle cx="100" cy="100" r="7" fill="#ffffff"/>
|
||||
<circle cx="122" cy="100" r="7" fill="#ffffff"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 375 B |
10
src/assets/sbgl-icons/radar.svg
Normal file
@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
|
||||
<circle cx="100" cy="100" r="92" fill="#6b5bd2"/>
|
||||
<path d="M100 42 A58 58 0 0 1 158 100" fill="none" stroke="#ffffff" stroke-width="10" stroke-linecap="round"/>
|
||||
<path d="M100 64 A36 36 0 0 1 136 100" fill="none" stroke="#ffffff" stroke-width="8" stroke-linecap="round" opacity="0.75"/>
|
||||
<path d="M100 100 L150 50" stroke="#ffffff" stroke-width="10" stroke-linecap="round"/>
|
||||
<circle cx="100" cy="100" r="13" fill="#ffffff"/>
|
||||
<circle cx="150" cy="50" r="9" fill="#ffd54f"/>
|
||||
<rect x="92" y="148" width="16" height="20" rx="4" fill="#ffffff"/>
|
||||
<rect x="68" y="164" width="64" height="10" rx="5" fill="#ffffff"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 693 B |
8
src/assets/sbgl-icons/roadline.svg
Normal file
@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
|
||||
<circle cx="100" cy="100" r="92" fill="#3a3f47"/>
|
||||
<path d="M58 160 L78 40" stroke="#ffd54f" stroke-width="10" stroke-linecap="round"/>
|
||||
<path d="M142 160 L122 40" stroke="#ffd54f" stroke-width="10" stroke-linecap="round"/>
|
||||
<path d="M100 160 V138" stroke="#ffffff" stroke-width="10" stroke-linecap="round"/>
|
||||
<path d="M100 116 V94" stroke="#ffffff" stroke-width="10" stroke-linecap="round"/>
|
||||
<path d="M100 72 V50" stroke="#ffffff" stroke-width="10" stroke-linecap="round"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 553 B |
7
src/assets/sbgl-icons/signboard.svg
Normal file
@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
|
||||
<circle cx="100" cy="100" r="92" fill="#2b7de9"/>
|
||||
<rect x="42" y="38" width="116" height="76" rx="10" fill="#ffffff"/>
|
||||
<path d="M100 50 L130 84 H113 V104 H87 V84 H70 Z" fill="#2b7de9"/>
|
||||
<rect x="92" y="114" width="16" height="46" rx="4" fill="#ffffff"/>
|
||||
<rect x="68" y="156" width="64" height="12" rx="6" fill="#ffffff"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 402 B |
8
src/assets/sbgl-icons/warning-post.svg
Normal file
@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
|
||||
<circle cx="100" cy="100" r="92" fill="#ef6c00"/>
|
||||
<rect x="80" y="32" width="40" height="114" rx="12" fill="#ffffff"/>
|
||||
<rect x="80" y="62" width="40" height="16" fill="#ef6c00"/>
|
||||
<rect x="80" y="104" width="40" height="16" fill="#ef6c00"/>
|
||||
<circle cx="100" cy="47" r="6" fill="#ef6c00"/>
|
||||
<rect x="60" y="146" width="80" height="16" rx="8" fill="#ffffff"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 438 B |
@ -46,7 +46,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { propTypes } from '@/utils/propTypes';
|
||||
import { delOss, listByIds } from '@/api/system/oss';
|
||||
import { businessUploadUrl, listBusinessOss, deleteBusinessOss } from '@/api/sbgl/common';
|
||||
import { globalHeaders } from '@/utils/request';
|
||||
|
||||
const props = defineProps({
|
||||
@ -71,8 +71,7 @@ const emit = defineEmits(['update:modelValue']);
|
||||
const number = ref(0);
|
||||
const uploadList = ref<any[]>([]);
|
||||
|
||||
const baseUrl = import.meta.env.VITE_APP_BASE_API;
|
||||
const uploadFileUrl = ref(baseUrl + '/resource/oss/upload'); // 上传文件服务器地址
|
||||
const uploadFileUrl = ref(businessUploadUrl); // 上传文件服务器地址
|
||||
const headers = ref(globalHeaders());
|
||||
|
||||
const fileList = ref<any[]>([]);
|
||||
@ -93,7 +92,7 @@ watch(
|
||||
if (Array.isArray(val)) {
|
||||
list = val;
|
||||
} else {
|
||||
const res = await listByIds(val);
|
||||
const res = await listBusinessOss(val);
|
||||
list = res.data.map((oss) => {
|
||||
return {
|
||||
name: oss.originalName,
|
||||
@ -177,7 +176,7 @@ const handleUploadSuccess = (res: any, file: UploadFile) => {
|
||||
// 删除文件
|
||||
const handleDelete = (index: number) => {
|
||||
const ossId = fileList.value[index].ossId;
|
||||
delOss(ossId);
|
||||
deleteBusinessOss(ossId);
|
||||
fileList.value.splice(index, 1);
|
||||
emit('update:modelValue', listToString(fileList.value));
|
||||
};
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { listByIds, delOss } from '@/api/system/oss';
|
||||
import { businessUploadUrl, listBusinessOss, deleteBusinessOss } from '@/api/sbgl/common';
|
||||
import { OssVO } from '@/api/system/oss/types';
|
||||
import { propTypes } from '@/utils/propTypes';
|
||||
import { globalHeaders } from '@/utils/request';
|
||||
@ -79,8 +79,7 @@ const uploadList = ref<any[]>([]);
|
||||
const dialogImageUrl = ref('');
|
||||
const dialogVisible = ref(false);
|
||||
|
||||
const baseUrl = import.meta.env.VITE_APP_BASE_API;
|
||||
const uploadImgUrl = ref(baseUrl + '/resource/oss/upload'); // 上传的图片服务器地址
|
||||
const uploadImgUrl = ref(businessUploadUrl); // 上传的图片服务器地址
|
||||
const headers = ref(globalHeaders());
|
||||
|
||||
const fileList = ref<any[]>([]);
|
||||
@ -100,7 +99,7 @@ watch(
|
||||
if (Array.isArray(val)) {
|
||||
list = val as OssVO[];
|
||||
} else {
|
||||
const res = await listByIds(val);
|
||||
const res = await listBusinessOss(val);
|
||||
list = res.data;
|
||||
}
|
||||
// 然后将数组转为对象数组
|
||||
@ -190,7 +189,7 @@ const handleDelete = (file: UploadFile): boolean => {
|
||||
const findex = fileList.value.map((f) => f.name).indexOf(file.name);
|
||||
if (findex > -1 && uploadList.value.length === number.value) {
|
||||
const ossId = fileList.value[findex].ossId;
|
||||
delOss(ossId);
|
||||
deleteBusinessOss(ossId);
|
||||
fileList.value.splice(findex, 1);
|
||||
emit('update:modelValue', listToString(fileList.value));
|
||||
return false;
|
||||
|
||||
@ -8,6 +8,14 @@ import captureIcon from '@/assets/sbgl-icons/capture.png';
|
||||
import warnIcon from '@/assets/sbgl-icons/warn.png';
|
||||
import pinIcon from '@/assets/sbgl-icons/pin.png';
|
||||
import markerIcon from '@/assets/sbgl-icons/marker.png';
|
||||
import ledIcon from '@/assets/sbgl-icons/led.svg';
|
||||
import radarIcon from '@/assets/sbgl-icons/radar.svg';
|
||||
import otherPowerIcon from '@/assets/sbgl-icons/other-power.svg';
|
||||
import signboardIcon from '@/assets/sbgl-icons/signboard.svg';
|
||||
import barrierIcon from '@/assets/sbgl-icons/barrier.svg';
|
||||
import roadlineIcon from '@/assets/sbgl-icons/roadline.svg';
|
||||
import warningPostIcon from '@/assets/sbgl-icons/warning-post.svg';
|
||||
import otherIcon from '@/assets/sbgl-icons/other.svg';
|
||||
|
||||
export interface IconOption {
|
||||
key: string;
|
||||
@ -18,8 +26,16 @@ export interface IconOption {
|
||||
/** 内置图标库(icon 字段存 key) */
|
||||
export const ICON_OPTIONS: IconOption[] = [
|
||||
{ key: 'signal', label: '信号灯', url: signalIcon },
|
||||
{ key: 'camera', label: '监控摄像头', url: cameraIcon },
|
||||
{ key: 'capture', label: '卡口/电警', url: captureIcon },
|
||||
{ key: 'camera', label: '电子监控', url: cameraIcon },
|
||||
{ key: 'led', label: 'LED诱导屏', url: ledIcon },
|
||||
{ key: 'radar', label: '雷达设备', url: radarIcon },
|
||||
{ key: 'other_power', label: '其他(带电)', url: otherPowerIcon },
|
||||
{ key: 'signboard', label: '交通标志牌', url: signboardIcon },
|
||||
{ key: 'barrier', label: '隔离护栏', url: barrierIcon },
|
||||
{ key: 'roadline', label: '交通标线', url: roadlineIcon },
|
||||
{ key: 'warning_post', label: '警示柱', url: warningPostIcon },
|
||||
{ key: 'other', label: '其他(不带电)', url: otherIcon },
|
||||
{ key: 'capture', label: '卡口/电子警察', url: captureIcon },
|
||||
{ key: 'warn', label: '警示标志', url: warnIcon },
|
||||
{ key: 'marker', label: '标记点', url: markerIcon },
|
||||
{ key: 'pin', label: '定位针', url: pinIcon }
|
||||
|
||||
@ -70,6 +70,19 @@ export const constantRoutes: RouteRecordRaw[] = [
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/sbgl/device/detail',
|
||||
component: Layout,
|
||||
hidden: true,
|
||||
children: [
|
||||
{
|
||||
path: ':id',
|
||||
component: () => import('@/views/sbgl/device/detail.vue'),
|
||||
name: 'SbDeviceDetail',
|
||||
meta: { title: '设备详情', activeMenu: '/sbgl/device', noCache: true }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/screen',
|
||||
component: () => import('@/views/sbgl/screen/index.vue'),
|
||||
|
||||
@ -1,23 +1,15 @@
|
||||
<template>
|
||||
<div class="app-container home">
|
||||
<div class="home-title">RuoYi-Vue-Plus 内网模板工程</div>
|
||||
<div class="home">
|
||||
<sbgl-stats />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="Index" lang="ts"></script>
|
||||
<script setup name="Index" lang="ts">
|
||||
import SbglStats from '@/views/sbgl/stats/index.vue';
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.home {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 60vh;
|
||||
|
||||
.home-title {
|
||||
font-size: 32px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 2px;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
min-height: calc(100vh - 120px);
|
||||
}
|
||||
</style>
|
||||
|
||||
417
src/views/sbgl/device/detail.vue
Normal file
@ -0,0 +1,417 @@
|
||||
<template>
|
||||
<div v-loading="loading" class="p-2 device-detail">
|
||||
<el-card shadow="hover" class="mb-3">
|
||||
<div class="detail-head">
|
||||
<div class="head-main">
|
||||
<el-button icon="ArrowLeft" circle @click="goBack" />
|
||||
<div class="head-text">
|
||||
<div class="title-row">
|
||||
<span class="detail-title">{{ device?.deviceName || '设备详情' }}</span>
|
||||
<dict-tag v-if="device" :options="sb_device_status" :value="device.status" />
|
||||
</div>
|
||||
<div class="detail-sub">
|
||||
<span>设备编号:{{ device?.deviceCode || '-' }}</span>
|
||||
<el-divider direction="vertical" />
|
||||
<span>设备类型:{{ device?.typeName || '-' }}</span>
|
||||
<el-divider direction="vertical" />
|
||||
<span>所属辖区:{{ device?.deptName || '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="head-actions">
|
||||
<el-button icon="Refresh" @click="loadDetail">刷新</el-button>
|
||||
<el-button v-if="device?.qrcode" type="primary" plain icon="Download" @click="downloadQrcode">下载二维码</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<template v-if="device">
|
||||
<el-row :gutter="12">
|
||||
<el-col :xs="24" :lg="16">
|
||||
<el-card shadow="hover" class="mb-3">
|
||||
<template #header><span class="card-title">基本信息</span></template>
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item label="设备编号">{{ device.deviceCode || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="设备名称">{{ device.deviceName || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="设备类型">{{ device.typeName || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="设备状态">
|
||||
<dict-tag :options="sb_device_status" :value="device.status" />
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="所属辖区">{{ device.deptName || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="安装日期">{{ formatDate(device.installDate, '{y}-{m}-{d}') }}</el-descriptions-item>
|
||||
<el-descriptions-item label="经度">{{ device.lng ?? '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="纬度">{{ device.lat ?? '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="安装位置" :span="2">{{ device.installLocation || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="报废日期">{{ formatDate(device.scrapDate, '{y}-{m}-{d}') }}</el-descriptions-item>
|
||||
<el-descriptions-item label="报废原因">{{ device.scrapReason || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="备注" :span="2">
|
||||
<span class="pre-wrap">{{ device.remark || '-' }}</span>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="hover" class="mb-3">
|
||||
<template #header><span class="card-title">扩展信息</span></template>
|
||||
<el-descriptions v-if="fields.length" :column="2" border>
|
||||
<el-descriptions-item v-for="f in fields" :key="f.fieldKey" :label="f.fieldLabel"
|
||||
:span="isWideField(f) ? 2 : 1">
|
||||
<template v-if="f.fieldType === 'image'">
|
||||
<div v-if="fileEntries(attrs[f.fieldKey]).length" class="detail-image-list">
|
||||
<el-image v-for="(img, idx) in fileEntries(attrs[f.fieldKey])" :key="idx" :src="img.url"
|
||||
:preview-src-list="fileEntries(attrs[f.fieldKey]).map((item) => item.url)" :initial-index="idx"
|
||||
fit="cover" preview-teleported class="detail-image" />
|
||||
</div>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template v-else-if="f.fieldType === 'file'">
|
||||
<div v-if="fileEntries(attrs[f.fieldKey]).length" class="detail-file-list">
|
||||
<el-link v-for="(file, idx) in fileEntries(attrs[f.fieldKey])" :key="idx" type="primary"
|
||||
:href="file.url" target="_blank" :underline="false">
|
||||
{{ file.name }}
|
||||
</el-link>
|
||||
</div>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<el-link v-else-if="f.fieldType === 'url' && isHttpUrl(attrs[f.fieldKey])" type="primary"
|
||||
:href="attrs[f.fieldKey]" target="_blank" :underline="false">
|
||||
{{ attrs[f.fieldKey] }}
|
||||
</el-link>
|
||||
<span v-else-if="f.fieldType === 'color' && attrs[f.fieldKey]" class="color-value">
|
||||
<i :style="{ backgroundColor: attrs[f.fieldKey] }"></i>{{ attrs[f.fieldKey] }}
|
||||
</span>
|
||||
<el-rate v-else-if="f.fieldType === 'rate' && hasValue(attrs[f.fieldKey])"
|
||||
:model-value="Number(attrs[f.fieldKey])" disabled />
|
||||
<div v-else-if="f.fieldType === 'checkbox' || f.fieldType === 'multiselect'" class="detail-tags">
|
||||
<template v-if="fieldValueArray(attrs[f.fieldKey]).length">
|
||||
<el-tag v-for="v in fieldValueArray(attrs[f.fieldKey])" :key="v" size="small" type="info">{{ v }}</el-tag>
|
||||
</template>
|
||||
<span v-else>-</span>
|
||||
</div>
|
||||
<span v-else class="pre-wrap">{{ formatFieldValue(f.fieldType, attrs[f.fieldKey]) }}</span>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
<el-empty v-else description="该设备类型暂未配置扩展字段" :image-size="70" />
|
||||
</el-card>
|
||||
|
||||
<el-card v-if="extraAttrs.length" shadow="hover" class="mb-3">
|
||||
<template #header><span class="card-title">其他属性</span></template>
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item v-for="[key, value] in extraAttrs" :key="key" :label="key">
|
||||
<span class="pre-wrap">{{ formatExtraValue(value) }}</span>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-card>
|
||||
</el-col>
|
||||
|
||||
<el-col :xs="24" :lg="8">
|
||||
<el-card shadow="hover" class="mb-3">
|
||||
<template #header><span class="card-title">设备二维码</span></template>
|
||||
<div class="qr-box">
|
||||
<el-image v-if="device.qrcode" :src="device.qrcode" :preview-src-list="[device.qrcode]"
|
||||
fit="contain" preview-teleported class="detail-qr" />
|
||||
<el-empty v-else description="暂无二维码" :image-size="70" />
|
||||
<div class="qr-code-text">{{ device.deviceCode || '-' }}</div>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="hover" class="mb-3">
|
||||
<template #header><span class="card-title">档案概览</span></template>
|
||||
<el-descriptions :column="1" border size="small">
|
||||
<el-descriptions-item label="建档时间">{{ formatDate(device.createTime) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="最近更新">{{ formatDate(device.updateTime) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="累计维修">{{ lifecycle?.repairCount ?? 0 }} 次</el-descriptions-item>
|
||||
<el-descriptions-item label="生命周期节点">{{ lifecycle?.timeline?.length ?? 0 }} 条</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-card shadow="hover">
|
||||
<template #header><span class="card-title">生命周期</span></template>
|
||||
<el-timeline v-if="lifecycle?.timeline?.length">
|
||||
<el-timeline-item v-for="(item, idx) in lifecycle.timeline" :key="idx"
|
||||
:timestamp="formatDate(item.time)" placement="top">
|
||||
<div class="timeline-content">{{ item.content }}</div>
|
||||
<div v-if="item.operator || item.orderId" class="timeline-meta">
|
||||
<span v-if="item.operator">操作人:{{ item.operator }}</span>
|
||||
<span v-if="item.orderId">关联工单:{{ item.orderId }}</span>
|
||||
</div>
|
||||
</el-timeline-item>
|
||||
</el-timeline>
|
||||
<el-empty v-else description="暂无生命周期记录" :image-size="70" />
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<el-empty v-else-if="!loading" description="设备不存在或无权访问">
|
||||
<el-button type="primary" @click="goBack">返回台账</el-button>
|
||||
</el-empty>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="DeviceDetail" lang="ts">
|
||||
import { listDetailFields } from '@/api/sbgl/devicetype';
|
||||
import { DeviceFieldVO } from '@/api/sbgl/devicetype/types';
|
||||
import { getDevice, getLifecycle } from '@/api/sbgl/device';
|
||||
import { DeviceVO, LifecycleVO } from '@/api/sbgl/device/types';
|
||||
import { listBusinessOss } from '@/api/sbgl/common';
|
||||
import { fieldValueArray, formatFieldValue } from '../devicetype/fieldTypes';
|
||||
|
||||
interface OssEntry {
|
||||
url: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
const { sb_device_status } = toRefs<any>(proxy?.useDict('sb_device_status'));
|
||||
|
||||
const loading = ref(true);
|
||||
const device = ref<DeviceVO | null>(null);
|
||||
const fields = ref<DeviceFieldVO[]>([]);
|
||||
const lifecycle = ref<LifecycleVO | null>(null);
|
||||
const ossMap = ref<Record<string, OssEntry>>({});
|
||||
|
||||
const deviceId = computed(() => String(route.params.id ?? ''));
|
||||
const attrs = computed<Record<string, any>>(() => parseAttrs(device.value?.attrs));
|
||||
|
||||
/** 后端 attrs 为 JSON 字符串,详情展示前解析为对象 */
|
||||
function parseAttrs(value: any): Record<string, any> {
|
||||
if (!value) return {};
|
||||
if (typeof value === 'object') return value;
|
||||
try {
|
||||
return JSON.parse(value);
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
const hasValue = (value: any): boolean => value !== null && value !== undefined && value !== '';
|
||||
const isHttpUrl = (value: any): boolean => /^https?:\/\//i.test(String(value ?? ''));
|
||||
const isWideField = (field: DeviceFieldVO): boolean => ['textarea', 'image', 'file'].includes(field.fieldType);
|
||||
|
||||
const formatDate = (value?: string | Date | null, pattern = '{y}-{m}-{d} {h}:{i}:{s}'): string => {
|
||||
if (!value) return '-';
|
||||
return proxy?.parseTime(value, pattern) ?? '-';
|
||||
};
|
||||
|
||||
/** 图片/附件字段存 OSS 文件ID,详情展示前批量换取访问地址 */
|
||||
const loadOssUrls = async () => {
|
||||
const ids = new Set<string>();
|
||||
for (const field of fields.value) {
|
||||
if (field.fieldType === 'image' || field.fieldType === 'file') {
|
||||
fieldValueArray(attrs.value[field.fieldKey]).forEach((id) => {
|
||||
if (/^\d+$/.test(id)) ids.add(id);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!ids.size) return;
|
||||
try {
|
||||
const res = await listBusinessOss([...ids].join(','));
|
||||
const map: Record<string, OssEntry> = { ...ossMap.value };
|
||||
(res.data ?? []).forEach((oss: any) => {
|
||||
map[String(oss.ossId)] = { url: oss.url, name: oss.originalName || String(oss.ossId) };
|
||||
});
|
||||
ossMap.value = map;
|
||||
} catch {
|
||||
// 附件地址解析失败不影响详情展示
|
||||
}
|
||||
};
|
||||
|
||||
/** 图片/附件值转为可访问地址,历史数据可能直接存 URL */
|
||||
const fileEntries = (value: any): OssEntry[] =>
|
||||
fieldValueArray(value)
|
||||
.map((item) => {
|
||||
if (isHttpUrl(item)) {
|
||||
let name = item;
|
||||
try {
|
||||
name = decodeURIComponent(item.split('?')[0].split('/').pop() || item);
|
||||
} catch {
|
||||
// 非标准 URL,保留原值
|
||||
}
|
||||
return { url: item, name };
|
||||
}
|
||||
const oss = ossMap.value[item];
|
||||
return { url: oss?.url ?? '', name: oss?.name || '附件' };
|
||||
})
|
||||
.filter((entry) => !!entry.url);
|
||||
|
||||
/** attrs 中未被字段配置覆盖的值也完整展示 */
|
||||
const extraAttrs = computed<Array<[string, any]>>(() => {
|
||||
const fieldKeys = new Set(fields.value.map((field) => field.fieldKey));
|
||||
return Object.entries(attrs.value).filter(
|
||||
([key, value]) => !fieldKeys.has(key) && value !== null && value !== undefined && value !== ''
|
||||
);
|
||||
});
|
||||
|
||||
const formatExtraValue = (value: any): string => {
|
||||
if (value === null || value === undefined || value === '') return '-';
|
||||
return typeof value === 'object' ? JSON.stringify(value) : String(value);
|
||||
};
|
||||
|
||||
const loadDetail = async () => {
|
||||
if (!deviceId.value) {
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
try {
|
||||
const res = await getDevice(deviceId.value);
|
||||
const data = res.data;
|
||||
device.value = data ? { ...data, attrs: parseAttrs(data.attrs) } : null;
|
||||
if (device.value?.typeId) {
|
||||
try {
|
||||
const fieldRes = await listDetailFields(device.value.typeId);
|
||||
fields.value = fieldRes.data ?? [];
|
||||
} catch {
|
||||
fields.value = [];
|
||||
}
|
||||
}
|
||||
try {
|
||||
const lifecycleRes = await getLifecycle(deviceId.value);
|
||||
lifecycle.value = lifecycleRes.data;
|
||||
} catch {
|
||||
lifecycle.value = null;
|
||||
}
|
||||
await loadOssUrls();
|
||||
} catch {
|
||||
device.value = null;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const downloadQrcode = () => {
|
||||
if (!device.value?.qrcode) return;
|
||||
const link = document.createElement('a');
|
||||
link.href = device.value.qrcode;
|
||||
link.download = `${device.value.deviceCode || 'device'}-二维码.png`;
|
||||
link.click();
|
||||
};
|
||||
|
||||
const goBack = () => router.push('/sbgl/device');
|
||||
|
||||
onMounted(loadDetail);
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.device-detail {
|
||||
.detail-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.head-main {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.detail-title {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
|
||||
.detail-sub {
|
||||
margin-top: 6px;
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.head-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.pre-wrap {
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.detail-image-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.detail-image {
|
||||
width: 88px;
|
||||
height: 88px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.detail-file-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.detail-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.color-value {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
|
||||
i {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 3px;
|
||||
border: 1px solid var(--el-border-color);
|
||||
}
|
||||
}
|
||||
|
||||
.qr-box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.detail-qr {
|
||||
width: 190px;
|
||||
height: 190px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.qr-code-text {
|
||||
margin-top: 10px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
font-size: 14px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.timeline-content {
|
||||
font-size: 14px;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
|
||||
.timeline-meta {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -9,6 +9,11 @@
|
||||
<el-option v-for="t in typeOptions" :key="t.id" :label="t.typeName" :value="t.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="辖区" prop="deptId">
|
||||
<el-tree-select v-model="queryParams.deptId" :data="deptOptions" node-key="id"
|
||||
:props="{ label: 'label', children: 'children' } as any" value-key="id"
|
||||
check-strictly clearable filterable placeholder="全部辖区" style="width: 180px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="关键字" prop="keyword">
|
||||
<el-input v-model="keyword" placeholder="编号/名称" clearable style="width: 180px" @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
@ -38,13 +43,19 @@
|
||||
<el-col :span="1.5">
|
||||
<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['sbgl:device:export']">导出</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="success" plain icon="Grid" @click="handleQrcodeBatch" v-hasPermi="['sbgl:device:list']">批量二维码</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="info" plain icon="RefreshLeft" @click="openRecycle" v-hasPermi="['sbgl:device:edit']">回收站</el-button>
|
||||
</el-col>
|
||||
<right-toolbar v-model:show-search="showSearch" @query-table="getList" />
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<el-table v-loading="loading" :data="deviceList">
|
||||
<el-table-column label="设备编号" prop="deviceCode" width="140" fixed />
|
||||
<el-table-column label="设备名称" prop="deviceName" min-width="130" fixed />
|
||||
<el-table-column label="设备编号" prop="deviceCode" width="140" />
|
||||
<el-table-column label="设备名称" prop="deviceName" min-width="130" />
|
||||
<el-table-column label="类型" prop="typeName" width="110" />
|
||||
<el-table-column label="辖区" prop="deptName" width="130" />
|
||||
<el-table-column label="状态" align="center" width="90">
|
||||
@ -53,16 +64,53 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 动态属性列 -->
|
||||
<el-table-column v-for="f in activeFields" :key="f.fieldKey" :label="f.fieldLabel" min-width="110" show-overflow-tooltip>
|
||||
<template #default="scope">{{ scope.row.attrs?.[f.fieldKey] ?? '-' }}</template>
|
||||
<el-table-column v-for="f in activeFields" :key="f.fieldKey" :label="f.fieldLabel" min-width="120" show-overflow-tooltip>
|
||||
<template #default="scope">
|
||||
<template v-if="f.fieldType === 'image'">
|
||||
<div v-if="attrFileUrls(scope.row.attrs?.[f.fieldKey]).length" class="attr-image-cell">
|
||||
<el-image v-for="(url, idx) in attrFileUrls(scope.row.attrs?.[f.fieldKey]).slice(0, 3)" :key="idx"
|
||||
:src="url" :preview-src-list="attrFileUrls(scope.row.attrs?.[f.fieldKey])" :initial-index="idx"
|
||||
fit="cover" preview-teleported class="attr-thumb" />
|
||||
<span v-if="attrFileUrls(scope.row.attrs?.[f.fieldKey]).length > 3" class="attr-more">
|
||||
+{{ attrFileUrls(scope.row.attrs?.[f.fieldKey]).length - 3 }}
|
||||
</span>
|
||||
</div>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<template v-else-if="f.fieldType === 'file'">
|
||||
<el-link v-if="attrFileUrl(scope.row.attrs?.[f.fieldKey])" type="primary"
|
||||
:href="attrFileUrl(scope.row.attrs?.[f.fieldKey])" target="_blank" :underline="false">
|
||||
查看附件({{ fieldValueArray(scope.row.attrs?.[f.fieldKey]).length }})
|
||||
</el-link>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
<el-link v-else-if="f.fieldType === 'url' && isHttpUrl(scope.row.attrs?.[f.fieldKey])" type="primary"
|
||||
:href="scope.row.attrs[f.fieldKey]" target="_blank" :underline="false">
|
||||
{{ scope.row.attrs[f.fieldKey] }}
|
||||
</el-link>
|
||||
<span v-else-if="f.fieldType === 'color' && scope.row.attrs?.[f.fieldKey]" class="attr-color">
|
||||
<i :style="{ backgroundColor: scope.row.attrs[f.fieldKey] }"></i>{{ scope.row.attrs[f.fieldKey] }}
|
||||
</span>
|
||||
<el-rate v-else-if="f.fieldType === 'rate' && scope.row.attrs?.[f.fieldKey] !== undefined && scope.row.attrs?.[f.fieldKey] !== ''"
|
||||
:model-value="Number(scope.row.attrs[f.fieldKey])" disabled size="small" />
|
||||
<span v-else>{{ formatFieldValue(f.fieldType, scope.row.attrs?.[f.fieldKey]) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="安装日期" prop="installDate" width="100">
|
||||
<template #default="scope">{{ scope.row.installDate ? proxy?.parseTime(scope.row.installDate, '{y}-{m}-{d}') : '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="260" fixed="right" align="center">
|
||||
<el-table-column label="安装位置" prop="installLocation" min-width="150" show-overflow-tooltip />
|
||||
<el-table-column label="二维码" width="80" align="center">
|
||||
<template #default="scope">
|
||||
<el-image v-if="scope.row.qrcode" :src="scope.row.qrcode" :preview-src-list="[scope.row.qrcode]"
|
||||
fit="contain" preview-teleported class="qr-thumb" />
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="280" align="center">
|
||||
<template #default="scope">
|
||||
<el-button link type="primary" icon="View" @click="goDetail(scope.row)" v-hasPermi="['sbgl:device:query']">详情</el-button>
|
||||
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['sbgl:device:edit']">修改</el-button>
|
||||
<el-button link type="primary" icon="View" @click="openLifecycle(scope.row)">履历</el-button>
|
||||
<el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['sbgl:device:remove']">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@ -76,8 +124,8 @@
|
||||
<el-row :gutter="12">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="设备类型" prop="typeId">
|
||||
<el-select v-model="form.typeId" placeholder="请选择类型" :disabled="!!form.id" style="width: 100%" @change="onFormTypeChange">
|
||||
<el-option v-for="t in typeOptions" :key="t.id" :label="t.typeName" :value="t.id" />
|
||||
<el-select v-model="form.typeId" placeholder="请选择类型" :disabled="!!form.id && !currentTypeDeleted" style="width: 100%" @change="onFormTypeChange">
|
||||
<el-option v-for="t in formTypeOptions" :key="t.id" :label="t.typeName" :value="t.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@ -125,19 +173,56 @@
|
||||
<el-button icon="Location" @click="mapPickVisible = true">在地图上选取位置</el-button>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="安装位置" prop="installLocation">
|
||||
<el-input v-model="form.installLocation" maxlength="200" placeholder="如:XX路与XX路交叉口东侧" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<!-- 动态属性字段(独立于列表动态列,避免污染列表展示) -->
|
||||
<el-col v-for="f in formFields" :key="f.fieldKey" :span="12">
|
||||
<el-form-item :label="f.fieldLabel" :prop="`attrs.${f.fieldKey}`"
|
||||
:rules="f.requiredFlag === 1 ? [{ required: true, message: `${f.fieldLabel}不能为空`, trigger: 'blur' }] : []">
|
||||
<el-select v-if="f.fieldType === 'radio'" v-model="form.attrs[f.fieldKey]" clearable style="width: 100%">
|
||||
<el-option v-for="opt in parseOptions(f.options)" :key="opt" :label="opt" :value="opt" />
|
||||
<el-col v-for="f in formFields" :key="f.fieldKey" :span="isWideField(f.fieldType) ? 24 : 12">
|
||||
<el-form-item :label="f.fieldLabel" :prop="`attrs.${f.fieldKey}`" :rules="fieldRules(f)">
|
||||
<el-input v-if="f.fieldType === 'textarea'" v-model="form.attrs[f.fieldKey]" type="textarea" :rows="3"
|
||||
:placeholder="`请输入${f.fieldLabel}`" />
|
||||
<el-select v-else-if="f.fieldType === 'select'" v-model="form.attrs[f.fieldKey]" clearable filterable
|
||||
:placeholder="`请选择${f.fieldLabel}`" style="width: 100%">
|
||||
<el-option v-for="opt in parseFieldOptions(f.options)" :key="opt" :label="opt" :value="opt" />
|
||||
</el-select>
|
||||
<el-select v-else-if="f.fieldType === 'checkbox'" v-model="form.attrs[f.fieldKey]" multiple style="width: 100%">
|
||||
<el-option v-for="opt in parseOptions(f.options)" :key="opt" :label="opt" :value="opt" />
|
||||
<el-select v-else-if="f.fieldType === 'multiselect'" v-model="form.attrs[f.fieldKey]" multiple clearable filterable
|
||||
:placeholder="`请选择${f.fieldLabel}`" style="width: 100%">
|
||||
<el-option v-for="opt in parseFieldOptions(f.options)" :key="opt" :label="opt" :value="opt" />
|
||||
</el-select>
|
||||
<el-date-picker v-else-if="f.fieldType === 'date'" v-model="form.attrs[f.fieldKey]" type="date" value-format="YYYY-MM-DD" style="width: 100%" />
|
||||
<el-input-number v-else-if="f.fieldType === 'number'" v-model="form.attrs[f.fieldKey]" :controls="false" style="width: 100%" />
|
||||
<el-input v-else v-model="form.attrs[f.fieldKey]" />
|
||||
<el-radio-group v-else-if="f.fieldType === 'radio'" v-model="form.attrs[f.fieldKey]">
|
||||
<el-radio v-for="opt in parseFieldOptions(f.options)" :key="opt" :value="opt">{{ opt }}</el-radio>
|
||||
</el-radio-group>
|
||||
<el-checkbox-group v-else-if="f.fieldType === 'checkbox'" v-model="form.attrs[f.fieldKey]">
|
||||
<el-checkbox v-for="opt in parseFieldOptions(f.options)" :key="opt" :value="opt">{{ opt }}</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
<el-date-picker v-else-if="f.fieldType === 'date'" v-model="form.attrs[f.fieldKey]" type="date"
|
||||
value-format="YYYY-MM-DD" :placeholder="`请选择${f.fieldLabel}`" style="width: 100%" />
|
||||
<el-date-picker v-else-if="f.fieldType === 'datetime'" v-model="form.attrs[f.fieldKey]" type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss" :placeholder="`请选择${f.fieldLabel}`" style="width: 100%" />
|
||||
<el-time-picker v-else-if="f.fieldType === 'time'" v-model="form.attrs[f.fieldKey]"
|
||||
value-format="HH:mm:ss" :placeholder="`请选择${f.fieldLabel}`" style="width: 100%" />
|
||||
<el-input-number v-else-if="f.fieldType === 'number'" v-model="form.attrs[f.fieldKey]" :controls="false"
|
||||
:placeholder="`请输入${f.fieldLabel}`" style="width: 100%" />
|
||||
<el-input-number v-else-if="f.fieldType === 'integer'" v-model="form.attrs[f.fieldKey]" :precision="0"
|
||||
:step="1" :placeholder="`请输入${f.fieldLabel}`" style="width: 100%" />
|
||||
<el-input-number v-else-if="f.fieldType === 'amount'" v-model="form.attrs[f.fieldKey]" :precision="2"
|
||||
:controls="false" placeholder="0.00" style="width: 100%" />
|
||||
<div v-else-if="f.fieldType === 'percent'" class="percent-input">
|
||||
<el-input-number v-model="form.attrs[f.fieldKey]" :min="0" :max="100" :precision="1" :controls="false"
|
||||
style="width: 100%" />
|
||||
<span class="percent-suffix">%</span>
|
||||
</div>
|
||||
<el-slider v-else-if="f.fieldType === 'slider'" v-model="form.attrs[f.fieldKey]" :min="0" :max="100" show-input />
|
||||
<el-rate v-else-if="f.fieldType === 'rate'" v-model="form.attrs[f.fieldKey]" />
|
||||
<el-switch v-else-if="f.fieldType === 'switch'" v-model="form.attrs[f.fieldKey]"
|
||||
:active-value="1" :inactive-value="0" />
|
||||
<el-color-picker v-else-if="f.fieldType === 'color'" v-model="form.attrs[f.fieldKey]" />
|
||||
<image-upload v-else-if="f.fieldType === 'image'" v-model="form.attrs[f.fieldKey]" :limit="5" />
|
||||
<file-upload v-else-if="f.fieldType === 'file'" v-model="form.attrs[f.fieldKey]" :limit="5" />
|
||||
<el-input v-else v-model="form.attrs[f.fieldKey]" :type="f.fieldType === 'email' ? 'email' : 'text'"
|
||||
:placeholder="`请输入${f.fieldLabel}`" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
@ -165,7 +250,7 @@
|
||||
<!-- 批量导入对话框 -->
|
||||
<el-dialog title="批量导入设备(Excel)" v-model="importVisible" width="620px" append-to-body>
|
||||
<el-alert type="info" :closable="false" class="mb-2"
|
||||
title="1. 选择设备类型并下载模板 → 2. 按模板填写 → 3. 上传导入;失败行会逐条给出原因。" />
|
||||
title="1. 选择设备类型并下载模板 → 2. 按模板填写 → 3. 上传导入;模板之外新增的列会自动创建为该类型的扩展字段。失败行会逐条给出原因。" />
|
||||
<el-form label-width="100px">
|
||||
<el-form-item label="设备类型">
|
||||
<el-select v-model="importForm.typeId" placeholder="请选择要导入的类型" style="width: 100%">
|
||||
@ -196,37 +281,55 @@
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 生命周期履历抽屉 -->
|
||||
<el-drawer v-model="lifecycleVisible" :title="`设备履历 - ${lifecycle?.deviceName || ''}`" size="560px">
|
||||
<template v-if="lifecycle">
|
||||
<el-descriptions :column="2" border size="small" class="mb-3">
|
||||
<el-descriptions-item label="设备编号">{{ lifecycle.deviceCode }}</el-descriptions-item>
|
||||
<el-descriptions-item label="当前状态">
|
||||
<dict-tag :options="sb_device_status" :value="lifecycle.status" />
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="建档时间">{{ proxy?.parseTime(lifecycle.createTime) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="累计维修次数">{{ lifecycle.repairCount }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
<el-timeline>
|
||||
<el-timeline-item v-for="(item, idx) in lifecycle.timeline" :key="idx" :timestamp="proxy?.parseTime(item.time)">
|
||||
{{ item.content }}
|
||||
<span v-if="item.operator" class="text-gray-400">({{ item.operator }})</span>
|
||||
</el-timeline-item>
|
||||
</el-timeline>
|
||||
</template>
|
||||
</el-drawer>
|
||||
<!-- 设备回收站 -->
|
||||
<el-dialog title="设备回收站" v-model="recycleVisible" width="920px" append-to-body>
|
||||
<el-form :inline="true" :model="recycleParams">
|
||||
<el-form-item label="设备编号">
|
||||
<el-input v-model="recycleKeyword" placeholder="请输入设备编号" clearable style="width: 170px" @keyup.enter="handleRecycleQuery" />
|
||||
</el-form-item>
|
||||
<el-form-item label="设备类型">
|
||||
<el-select v-model="recycleParams.typeId" placeholder="全部类型" clearable style="width: 160px">
|
||||
<el-option v-for="t in typeOptions" :key="t.id" :label="t.typeName" :value="t.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleRecycleQuery">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetRecycleQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-table v-loading="recycleLoading" :data="recycleList" size="small">
|
||||
<el-table-column label="设备编号" prop="deviceCode" width="140" />
|
||||
<el-table-column label="设备名称" prop="deviceName" min-width="130" show-overflow-tooltip />
|
||||
<el-table-column label="类型" prop="typeName" width="120" show-overflow-tooltip />
|
||||
<el-table-column label="辖区" prop="deptName" width="130" show-overflow-tooltip />
|
||||
<el-table-column label="状态" width="90" align="center">
|
||||
<template #default="scope">
|
||||
<dict-tag :options="sb_device_status" :value="scope.row.status" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="安装位置" prop="installLocation" min-width="150" show-overflow-tooltip />
|
||||
<el-table-column label="操作" width="90" align="center">
|
||||
<template #default="scope">
|
||||
<el-button link type="primary" @click="handleRestore(scope.row)">恢复</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<pagination v-show="recycleTotal > 0" v-model:page="recycleParams.pageNum" v-model:limit="recycleParams.pageSize"
|
||||
:total="recycleTotal" @pagination="loadRecycle" />
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="Device" lang="ts">
|
||||
import { listType, listTypeOptions, listEnabledFields } from '@/api/sbgl/devicetype';
|
||||
import { DeviceTypeVO, DeviceFieldVO } from '@/api/sbgl/devicetype/types';
|
||||
import { listDevice, getDevice, addDevice, updateDevice, delDevice, importTemplate, importData, exportDevice, getLifecycle } from '@/api/sbgl/device';
|
||||
import { DeviceVO, DeviceQuery, DeviceForm, ImportResultVO, LifecycleVO } from '@/api/sbgl/device/types';
|
||||
import { getCommonDeptTree } from '@/api/sbgl/common';
|
||||
|
||||
import { parseFieldOptions, fieldValueArray, formatFieldValue, normalizeFieldValue } from '../devicetype/fieldTypes';
|
||||
import { listDevice, getDevice, addDevice, updateDevice, delDevice, importTemplate, importData, exportDevice, listRecycleDevice, restoreDevice, exportDeviceQrcode } from '@/api/sbgl/device';
|
||||
import { DeviceVO, DeviceQuery, DeviceForm, ImportResultVO } from '@/api/sbgl/device/types';
|
||||
import { getCommonDeptTree, listBusinessOss } from '@/api/sbgl/common';
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
const { sb_device_status } = toRefs<any>(proxy?.useDict('sb_device_status'));
|
||||
const router = useRouter();
|
||||
|
||||
const deviceList = ref<DeviceVO[]>([]);
|
||||
const typeOptions = ref<DeviceTypeVO[]>([]);
|
||||
@ -253,8 +356,25 @@ const importForm = reactive({ typeId: '' as any, mode: 'add' as 'add' | 'upsert'
|
||||
const importResult = ref<ImportResultVO | null>(null);
|
||||
const fileInputRef = ref<HTMLInputElement>();
|
||||
|
||||
const lifecycleVisible = ref(false);
|
||||
const lifecycle = ref<LifecycleVO | null>(null);
|
||||
// ---------------- 回收站 ----------------
|
||||
const recycleVisible = ref(false);
|
||||
const recycleLoading = ref(false);
|
||||
const recycleList = ref<DeviceVO[]>([]);
|
||||
const recycleTotal = ref(0);
|
||||
const recycleKeyword = ref('');
|
||||
const recycleParams = ref<DeviceQuery>({ pageNum: 1, pageSize: 10 });
|
||||
|
||||
/** 当前编辑设备的类型已被删除:允许改选其他类型以便修复数据 */
|
||||
const currentTypeDeleted = ref(false);
|
||||
/** 编辑弹窗专用的“已删除类型”选项,不污染列表筛选与新增下拉 */
|
||||
const extraFormTypeOption = ref<DeviceTypeVO | null>(null);
|
||||
const formTypeOptions = computed<DeviceTypeVO[]>(() => {
|
||||
const extra = extraFormTypeOption.value;
|
||||
if (extra && !typeOptions.value.some((t) => String(t.id) === String(extra.id))) {
|
||||
return [extra, ...typeOptions.value];
|
||||
}
|
||||
return typeOptions.value;
|
||||
});
|
||||
|
||||
let form = ref<DeviceForm>({
|
||||
deviceCode: '',
|
||||
@ -271,12 +391,96 @@ const formRules = {
|
||||
typeId: [{ required: true, message: '设备类型不能为空', trigger: 'change' }]
|
||||
};
|
||||
|
||||
const parseOptions = (optionsJson?: string): string[] => {
|
||||
if (!optionsJson) return [];
|
||||
/** 宽字段控件占满整行 */
|
||||
const WIDE_FIELD_TYPES = ['textarea', 'image', 'file', 'slider'];
|
||||
const isWideField = (type?: string) => WIDE_FIELD_TYPES.includes(type ?? '');
|
||||
|
||||
/** 各类型的格式校验(为空时不校验,必填由 required 规则负责) */
|
||||
const formatValidator = (pattern: RegExp, message: string) => ({
|
||||
trigger: ['blur', 'change'],
|
||||
validator: (_rule: any, value: any, callback: any) => {
|
||||
if (value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0)) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
pattern.test(String(value)) ? callback() : callback(new Error(message));
|
||||
}
|
||||
});
|
||||
|
||||
const fieldRules = (f: DeviceFieldVO) => {
|
||||
const rules: any[] = [];
|
||||
if (f.requiredFlag === 1) {
|
||||
rules.push({ required: true, message: `${f.fieldLabel}不能为空`, trigger: ['blur', 'change'] });
|
||||
}
|
||||
switch (f.fieldType) {
|
||||
case 'email':
|
||||
rules.push(formatValidator(/^[\w.%+-]+@[\w.-]+\.[A-Za-z]{2,}$/, '请输入正确的邮箱地址'));
|
||||
break;
|
||||
case 'phone':
|
||||
rules.push(formatValidator(/^(?:(?:\+?86[- ]?)?1[3-9]\d{9}|0\d{2,3}-?\d{7,8}(?:-\d{1,6})?)$/, '请输入正确的手机号或座机号'));
|
||||
break;
|
||||
case 'url':
|
||||
rules.push(formatValidator(/^https?:\/\/\S+$/i, '请输入以 http:// 或 https:// 开头的链接'));
|
||||
break;
|
||||
case 'ip':
|
||||
rules.push(formatValidator(/^((25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)$/, '请输入正确的IPv4地址'));
|
||||
break;
|
||||
case 'color':
|
||||
rules.push(formatValidator(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/, '请输入十六进制颜色值,如 #FF0000'));
|
||||
break;
|
||||
}
|
||||
return rules;
|
||||
};
|
||||
|
||||
/** 仅 http(s) 链接可点击 */
|
||||
const isHttpUrl = (value: any): boolean => /^https?:\/\//i.test(String(value ?? ''));
|
||||
|
||||
/** 图片/附件字段存的是 OSS 文件ID,列表展示前批量换取访问地址 */
|
||||
const ossUrlMap = ref<Record<string, string>>({});
|
||||
|
||||
const loadAttrOssUrls = async () => {
|
||||
const ids = new Set<string>();
|
||||
for (const row of deviceList.value) {
|
||||
for (const f of activeFields.value) {
|
||||
if (f.fieldType === 'image' || f.fieldType === 'file') {
|
||||
fieldValueArray(row.attrs?.[f.fieldKey]).forEach((id) => ids.add(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
// 历史数据可能直接存了 URL,仅查询纯数字的 OSS 文件ID
|
||||
const idList = [...ids].filter((id) => /^\d+$/.test(id));
|
||||
if (!idList.length) return;
|
||||
try {
|
||||
return JSON.parse(optionsJson);
|
||||
const res = await listBusinessOss(idList.join(','));
|
||||
const map = { ...ossUrlMap.value };
|
||||
(res.data ?? []).forEach((oss: any) => (map[String(oss.ossId)] = oss.url));
|
||||
ossUrlMap.value = map;
|
||||
} catch {
|
||||
return optionsJson.split(/[,,]/).filter(Boolean);
|
||||
// 附件地址解析失败不影响列表展示
|
||||
}
|
||||
};
|
||||
|
||||
/** 单个图片/附件值转访问地址 */
|
||||
const attrFileUrl = (value: any, index = 0): string => {
|
||||
const item = fieldValueArray(value)[index];
|
||||
if (!item) return '';
|
||||
return isHttpUrl(item) ? item : (ossUrlMap.value[item] ?? '');
|
||||
};
|
||||
|
||||
/** 图片/附件全部可预览地址 */
|
||||
const attrFileUrls = (value: any): string[] =>
|
||||
fieldValueArray(value)
|
||||
.map((item) => (isHttpUrl(item) ? item : ossUrlMap.value[item] ?? ''))
|
||||
.filter(Boolean);
|
||||
|
||||
/** 后端 attrs 为 JSON 字符串,列表渲染前解析为对象 */
|
||||
const parseAttrsJson = (attrs: any): Record<string, any> => {
|
||||
if (!attrs) return {};
|
||||
if (typeof attrs === 'object') return attrs;
|
||||
try {
|
||||
return JSON.parse(attrs);
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
@ -284,8 +488,9 @@ const getList = async () => {
|
||||
loading.value = true;
|
||||
queryParams.value.deviceCode = keyword.value;
|
||||
const res = await listDevice(queryParams.value);
|
||||
deviceList.value = res.rows;
|
||||
deviceList.value = (res.rows ?? []).map((row) => ({ ...row, attrs: parseAttrsJson(row.attrs) }));
|
||||
total.value = res.total;
|
||||
await loadAttrOssUrls();
|
||||
loading.value = false;
|
||||
};
|
||||
|
||||
@ -321,8 +526,8 @@ const loadFormFields = async (typeId?: string | number) => {
|
||||
formFields.value = res.data ?? [];
|
||||
};
|
||||
|
||||
const handleTypeChanged = () => {
|
||||
loadActiveFields(queryParams.value.typeId);
|
||||
const handleTypeChanged = async () => {
|
||||
await loadActiveFields(queryParams.value.typeId);
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
@ -332,8 +537,20 @@ const onFormTypeChange = () => {
|
||||
loadFormFields(form.value.typeId);
|
||||
};
|
||||
|
||||
/** 回显时按字段类型归一化(多选字符串转数组、数值字符串转数字等) */
|
||||
const normalizeFormAttrs = () => {
|
||||
const attrs: Record<string, any> = { ...(form.value.attrs || {}) };
|
||||
for (const f of formFields.value) {
|
||||
attrs[f.fieldKey] = normalizeFieldValue(f.fieldType, attrs[f.fieldKey]);
|
||||
}
|
||||
form.value.attrs = attrs;
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
form.value = { deviceCode: '', deviceName: '', typeId: '' as any, status: '0', attrs: {} };
|
||||
formFields.value = [];
|
||||
currentTypeDeleted.value = false;
|
||||
extraFormTypeOption.value = null;
|
||||
deviceFormRef.value?.resetFields();
|
||||
};
|
||||
|
||||
@ -351,6 +568,18 @@ const handleUpdate = async (row: DeviceVO) => {
|
||||
resetForm();
|
||||
const res = await getDevice(row.id);
|
||||
const data = res.data;
|
||||
// 类型可能已被删除:补充一条选项,下拉才能显示原类型名称而不是ID,并允许改选其他类型
|
||||
currentTypeDeleted.value = !!data.typeId && !typeOptions.value.some((t) => String(t.id) === String(data.typeId));
|
||||
extraFormTypeOption.value = currentTypeDeleted.value
|
||||
? ({
|
||||
id: data.typeId,
|
||||
typeName: data.typeName || `已删除类型(${data.typeId})`,
|
||||
typeCode: '',
|
||||
needLocation: 0,
|
||||
sort: 0,
|
||||
status: '1'
|
||||
} as DeviceTypeVO)
|
||||
: null;
|
||||
form.value = {
|
||||
id: data.id,
|
||||
deviceCode: data.deviceCode,
|
||||
@ -360,13 +589,15 @@ const handleUpdate = async (row: DeviceVO) => {
|
||||
lng: data.lng,
|
||||
lat: data.lat,
|
||||
status: data.status,
|
||||
attrs: data.attrs ? (typeof data.attrs === 'string' ? JSON.parse(data.attrs) : data.attrs) : {},
|
||||
attrs: parseAttrsJson(data.attrs),
|
||||
installDate: data.installDate,
|
||||
installLocation: data.installLocation,
|
||||
scrapDate: data.scrapDate,
|
||||
scrapReason: data.scrapReason,
|
||||
remark: data.remark
|
||||
};
|
||||
await loadFormFields(data.typeId);
|
||||
normalizeFormAttrs();
|
||||
dialog.title = '修改设备';
|
||||
dialog.visible = true;
|
||||
};
|
||||
@ -374,7 +605,7 @@ const handleUpdate = async (row: DeviceVO) => {
|
||||
const submitForm = () => {
|
||||
deviceFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (!valid) return;
|
||||
const needLocation = typeOptions.value.find((t) => t.id === form.value.typeId)?.needLocation === 1;
|
||||
const needLocation = formTypeOptions.value.find((t) => String(t.id) === String(form.value.typeId))?.needLocation === 1;
|
||||
if (needLocation && (form.value.lng === undefined || form.value.lat === undefined)) {
|
||||
proxy?.$modal.msgWarning('该类型设备必须填写经纬度(可使用地图选点)');
|
||||
return;
|
||||
@ -392,12 +623,50 @@ const submitForm = () => {
|
||||
};
|
||||
|
||||
const handleDelete = async (row: DeviceVO) => {
|
||||
await proxy?.$modal.confirm(`是否删除设备"${row.deviceName}"?删除后数据保留可恢复。`);
|
||||
await proxy?.$modal.confirm(`是否删除设备"${row.deviceName}"?删除后可在回收站中恢复。`);
|
||||
await delDevice(row.id);
|
||||
getList();
|
||||
proxy?.$modal.msgSuccess('删除成功');
|
||||
};
|
||||
|
||||
// ---------------- 回收站 ----------------
|
||||
const loadRecycle = async () => {
|
||||
recycleLoading.value = true;
|
||||
try {
|
||||
const res = await listRecycleDevice({ ...recycleParams.value, deviceCode: recycleKeyword.value || undefined });
|
||||
recycleList.value = res.rows ?? [];
|
||||
recycleTotal.value = res.total;
|
||||
} finally {
|
||||
recycleLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const openRecycle = () => {
|
||||
recycleKeyword.value = '';
|
||||
recycleParams.value = { pageNum: 1, pageSize: 10 };
|
||||
recycleVisible.value = true;
|
||||
loadRecycle();
|
||||
};
|
||||
|
||||
const handleRecycleQuery = () => {
|
||||
recycleParams.value.pageNum = 1;
|
||||
loadRecycle();
|
||||
};
|
||||
|
||||
const resetRecycleQuery = () => {
|
||||
recycleKeyword.value = '';
|
||||
recycleParams.value = { pageNum: 1, pageSize: 10 };
|
||||
loadRecycle();
|
||||
};
|
||||
|
||||
const handleRestore = async (row: DeviceVO) => {
|
||||
await proxy?.$modal.confirm(`是否恢复设备"${row.deviceName}"?`);
|
||||
await restoreDevice(row.id);
|
||||
proxy?.$modal.msgSuccess('恢复成功');
|
||||
await loadRecycle();
|
||||
getList();
|
||||
};
|
||||
|
||||
const onPick = (point: { lng: number; lat: number }) => {
|
||||
form.value.lng = point.lng;
|
||||
form.value.lat = point.lat;
|
||||
@ -436,19 +705,110 @@ const handleExport = () => {
|
||||
});
|
||||
};
|
||||
|
||||
// ---------------- 生命周期 ----------------
|
||||
const openLifecycle = async (row: DeviceVO) => {
|
||||
const res = await getLifecycle(row.id);
|
||||
lifecycle.value = res.data;
|
||||
lifecycleVisible.value = true;
|
||||
// ---------------- 设备二维码 ----------------
|
||||
const handleQrcodeBatch = () => {
|
||||
proxy?.$modal.confirm('是否按当前筛选条件导出设备二维码?').then(() => {
|
||||
return exportDeviceQrcode({ ...queryParams.value, deviceCode: keyword.value || undefined });
|
||||
});
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
// ---------------- 详情 ----------------
|
||||
const goDetail = (row: DeviceVO) => {
|
||||
router.push(`/sbgl/device/detail/${row.id}`);
|
||||
};
|
||||
|
||||
/** 设备类型下拉:keep-alive 页面再次进入时需刷新,保证新增类型立即可见 */
|
||||
const loadTypeOptions = async () => {
|
||||
const typeRes = await listTypeOptions();
|
||||
typeOptions.value = typeRes.data ?? [];
|
||||
};
|
||||
|
||||
let typeOptionsActivated = false;
|
||||
|
||||
onMounted(async () => {
|
||||
await loadTypeOptions();
|
||||
// 所属辖区:按系统部门树选择(登录即可,与工单派单一致)
|
||||
const deptRes = await getCommonDeptTree();
|
||||
deptOptions.value = (deptRes.data ?? []) as any[];
|
||||
getList();
|
||||
});
|
||||
|
||||
onActivated(() => {
|
||||
// 首次激活由 onMounted 加载,之后每次从其他页签切回来都重新拉取类型
|
||||
if (typeOptionsActivated) {
|
||||
loadTypeOptions();
|
||||
}
|
||||
typeOptionsActivated = true;
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.attr-image-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
|
||||
.attr-thumb {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.attr-more {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
}
|
||||
|
||||
.attr-color {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
|
||||
i {
|
||||
display: inline-block;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
.percent-input {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
width: 100%;
|
||||
|
||||
.percent-suffix {
|
||||
color: #909399;
|
||||
}
|
||||
}
|
||||
|
||||
.qr-thumb {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.qr-preview {
|
||||
text-align: center;
|
||||
|
||||
.qr-image {
|
||||
width: 260px;
|
||||
height: 260px;
|
||||
}
|
||||
|
||||
.qr-code {
|
||||
margin-top: 8px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.qr-name {
|
||||
margin-top: 4px;
|
||||
color: #909399;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
182
src/views/sbgl/devicetype/fieldTypes.ts
Normal file
@ -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<string, FieldTypeMeta> = 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);
|
||||
}
|
||||
};
|
||||
@ -66,8 +66,8 @@
|
||||
<el-form-item label="类型名称" prop="typeName">
|
||||
<el-input v-model="form.typeName" placeholder="如:信号机" />
|
||||
</el-form-item>
|
||||
<el-form-item label="类型编码" prop="typeCode">
|
||||
<el-input v-model="form.typeCode" placeholder="如:signal_machine" />
|
||||
<el-form-item label="类型编码">
|
||||
<el-input v-model="form.typeCode" disabled :placeholder="form.id ? '' : '保存时根据类型名称自动生成'" />
|
||||
</el-form-item>
|
||||
<el-form-item label="地图图标">
|
||||
<div class="icon-picker">
|
||||
@ -76,6 +76,23 @@
|
||||
<img :src="opt.url" :alt="opt.label" />
|
||||
</div>
|
||||
</el-tooltip>
|
||||
<!-- 已新增的自定义图标(来自其他类型上传过的图标,可复用) -->
|
||||
<el-tooltip v-for="url in customIconOptions" :key="url" content="自定义图标" placement="top">
|
||||
<div :class="['icon-item', form.icon === url ? 'active' : '']" @click="form.icon = url">
|
||||
<img :src="url" alt="自定义图标" />
|
||||
<span v-if="form.icon === url" class="icon-remove" title="移除自定义图标" @click.stop="clearCustomIcon">×</span>
|
||||
</div>
|
||||
</el-tooltip>
|
||||
<!-- 新增图标:上传后自动选中 -->
|
||||
<el-tooltip content="新增图标(PNG/JPG/SVG/WEBP,不超过1MB)" placement="top">
|
||||
<el-upload class="icon-uploader" :action="uploadIconUrl" :headers="uploadHeaders"
|
||||
:show-file-list="false" accept=".png,.jpg,.jpeg,.svg,.webp"
|
||||
:before-upload="beforeIconUpload" :on-success="onIconUploadSuccess" :on-error="onIconUploadError">
|
||||
<div class="icon-item icon-add">
|
||||
<el-icon><plus /></el-icon>
|
||||
</div>
|
||||
</el-upload>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="需要经纬度">
|
||||
@ -102,36 +119,29 @@
|
||||
</el-dialog>
|
||||
|
||||
<!-- 属性字段配置抽屉 -->
|
||||
<el-drawer v-model="fieldDrawer.visible" :title="`属性字段配置 - ${fieldDrawer.typeName}`" size="780px">
|
||||
<el-drawer v-model="fieldDrawer.visible" :title="`属性字段配置 - ${fieldDrawer.typeName}`" size="880px">
|
||||
<el-alert type="info" :closable="false" class="mb-2"
|
||||
title="字段保存后,该类型设备的录入表单与列表列自动跟随变化;删除字段不影响历史数据。" />
|
||||
title="只需填写显示标签,字段键会根据标签自动生成(标签重复时自动追加序号);保存后表单与列表列自动跟随变化,删除字段不影响历史数据。" />
|
||||
<el-table :data="fieldList" size="small">
|
||||
<el-table-column label="显示标签" width="130">
|
||||
<el-table-column label="显示标签" width="160">
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.fieldLabel" placeholder="如:品牌" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="字段键" width="130">
|
||||
<el-table-column label="数据类型" width="150">
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.fieldKey" placeholder="如:brand" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="数据类型" width="110">
|
||||
<template #default="scope">
|
||||
<el-select v-model="scope.row.fieldType">
|
||||
<el-option label="文本" value="text" />
|
||||
<el-option label="数字" value="number" />
|
||||
<el-option label="日期" value="date" />
|
||||
<el-option label="单选" value="radio" />
|
||||
<el-option label="多选" value="checkbox" />
|
||||
<el-select v-model="scope.row.fieldType" filterable>
|
||||
<el-option-group v-for="group in FIELD_TYPE_GROUPS" :key="group.label" :label="group.label">
|
||||
<el-option v-for="opt in group.types" :key="opt.value" :label="opt.label" :value="opt.value" />
|
||||
</el-option-group>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="选项(逗号分隔)" min-width="150">
|
||||
<el-table-column label="选项(逗号分隔)" min-width="160">
|
||||
<template #default="scope">
|
||||
<el-input v-if="scope.row.fieldType === 'radio' || scope.row.fieldType === 'checkbox'"
|
||||
v-model="scope.row.options" placeholder="光纤,4G,5G" />
|
||||
<span v-else>-</span>
|
||||
<el-input v-if="needOptions(scope.row.fieldType)" v-model="scope.row.options"
|
||||
placeholder="光纤,4G,5G" />
|
||||
<span v-else class="text-gray-400">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="必填" width="60" align="center">
|
||||
@ -153,18 +163,39 @@
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-button class="mt-2" icon="Plus" @click="addFieldRow">添加字段</el-button>
|
||||
<el-button class="mt-2" icon="Delete" @click="openFieldRecycle">回收站</el-button>
|
||||
<template #footer>
|
||||
<el-button type="primary" :loading="fieldDrawer.saving" @click="saveFields" v-hasPermi="['sbgl:type:edit']">保存配置</el-button>
|
||||
<el-button @click="fieldDrawer.visible = false">取 消</el-button>
|
||||
</template>
|
||||
</el-drawer>
|
||||
|
||||
<!-- 字段回收站 -->
|
||||
<el-dialog v-model="fieldRecycle.visible" title="字段回收站" width="640px" append-to-body>
|
||||
<el-table v-if="fieldRecycle.list.length" :data="fieldRecycle.list" size="small">
|
||||
<el-table-column label="显示标签" prop="fieldLabel" />
|
||||
<el-table-column label="字段键" prop="fieldKey" />
|
||||
<el-table-column label="数据类型" prop="fieldType" width="120" />
|
||||
<el-table-column label="操作" width="90" align="center">
|
||||
<template #default="scope">
|
||||
<el-button link type="primary" @click="handleRestoreField(scope.row)">恢复</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-empty v-if="!fieldRecycle.list.length" description="暂无已删除字段" />
|
||||
<template #footer>
|
||||
<el-button @click="fieldRecycle.visible = false">关 闭</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="DeviceType" lang="ts">
|
||||
import { listType, getType, addType, updateType, delType, listFields, batchSaveFields } from '@/api/sbgl/devicetype';
|
||||
import { listType, listTypeOptions, getType, addType, updateType, delType, listFields, batchSaveFields, listDeletedFields, restoreField } from '@/api/sbgl/devicetype';
|
||||
import { DeviceTypeVO, DeviceTypeQuery, DeviceTypeForm, DeviceFieldVO } from '@/api/sbgl/devicetype/types';
|
||||
import { ICON_OPTIONS, DEFAULT_ICON_KEY, resolveIconUrl } from '@/components/SbMap/icons';
|
||||
import { globalHeaders } from '@/utils/request';
|
||||
import { FIELD_TYPE_GROUPS, needOptions, parseFieldOptions } from './fieldTypes';
|
||||
|
||||
const iconOptions = ICON_OPTIONS;
|
||||
|
||||
@ -192,10 +223,73 @@ let form = ref<DeviceTypeForm>({
|
||||
status: '0'
|
||||
});
|
||||
const fieldList = ref<DeviceFieldVO[]>([]);
|
||||
const fieldRecycle = reactive({ visible: false, list: [] as DeviceFieldVO[] });
|
||||
|
||||
// ---------------- 地图图标:内置图标 + 上传新增 ----------------
|
||||
const uploadIconUrl = import.meta.env.VITE_APP_BASE_API + '/resource/oss/upload';
|
||||
const uploadHeaders = globalHeaders();
|
||||
|
||||
/** 其他类型已使用过的自定义图标,可作为图标库复用 */
|
||||
const customIconUrls = ref<string[]>([]);
|
||||
|
||||
/** 当前图标是否为自定义上传地址(非内置图标 key) */
|
||||
const isCustomIcon = computed(() => !!form.value.icon && !ICON_OPTIONS.some((o) => o.key === form.value.icon));
|
||||
|
||||
/** 图标库:历史自定义图标 + 当前图标(避免编辑旧数据时缺失) */
|
||||
const customIconOptions = computed(() => {
|
||||
const list = [...customIconUrls.value];
|
||||
if (isCustomIcon.value && form.value.icon && !list.includes(form.value.icon)) {
|
||||
list.push(form.value.icon);
|
||||
}
|
||||
return list;
|
||||
});
|
||||
|
||||
const loadCustomIcons = async () => {
|
||||
try {
|
||||
const res = await listTypeOptions();
|
||||
const urls = (res.data ?? [])
|
||||
.map((t) => t.icon)
|
||||
.filter((icon): icon is string => !!icon && !ICON_OPTIONS.some((o) => o.key === icon));
|
||||
customIconUrls.value = [...new Set(urls)];
|
||||
} catch {
|
||||
// 图标库加载失败不影响类型编辑
|
||||
}
|
||||
};
|
||||
|
||||
const beforeIconUpload = (file: File) => {
|
||||
if (!/\.(png|jpe?g|svg|webp)$/i.test(file.name)) {
|
||||
proxy?.$modal.msgError('请上传 PNG/JPG/SVG/WEBP 格式的图标');
|
||||
return false;
|
||||
}
|
||||
if (file.size / 1024 / 1024 > 1) {
|
||||
proxy?.$modal.msgError('图标大小不能超过 1MB');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const onIconUploadSuccess = (res: any) => {
|
||||
if (res.code === 200 && res.data?.url) {
|
||||
form.value.icon = res.data.url;
|
||||
if (!customIconUrls.value.includes(res.data.url)) {
|
||||
customIconUrls.value = [...customIconUrls.value, res.data.url];
|
||||
}
|
||||
proxy?.$modal.msgSuccess('图标已新增并选中');
|
||||
} else {
|
||||
proxy?.$modal.msgError(res.msg || '图标上传失败');
|
||||
}
|
||||
};
|
||||
|
||||
const onIconUploadError = () => {
|
||||
proxy?.$modal.msgError('图标上传失败,请确认有文件上传权限');
|
||||
};
|
||||
|
||||
const clearCustomIcon = () => {
|
||||
form.value.icon = DEFAULT_ICON_KEY;
|
||||
};
|
||||
|
||||
const rules = {
|
||||
typeName: [{ required: true, message: '类型名称不能为空', trigger: 'blur' }],
|
||||
typeCode: [{ required: true, message: '类型编码不能为空', trigger: 'blur' }]
|
||||
typeName: [{ required: true, message: '类型名称不能为空', trigger: 'blur' }]
|
||||
};
|
||||
|
||||
const getList = async () => {
|
||||
@ -247,11 +341,12 @@ const submitForm = () => {
|
||||
}
|
||||
dialog.visible = false;
|
||||
getList();
|
||||
loadCustomIcons();
|
||||
});
|
||||
};
|
||||
|
||||
const handleDelete = async (row: DeviceTypeVO) => {
|
||||
await proxy?.$modal.confirm(`是否删除设备类型"${row.typeName}"?`);
|
||||
await proxy?.$modal.confirm(`是否删除设备类型"${row.typeName}"?该类型下存在设备时将无法删除。`);
|
||||
await delType(row.id);
|
||||
getList();
|
||||
proxy?.$modal.msgSuccess('删除成功');
|
||||
@ -268,7 +363,8 @@ const openFieldDrawer = async (row: DeviceTypeVO) => {
|
||||
fieldDrawer.typeName = row.typeName;
|
||||
fieldDrawer.visible = true;
|
||||
const res = await listFields(row.id);
|
||||
fieldList.value = res.data ?? [];
|
||||
// 选项统一显示为逗号分隔文本,避免历史 JSON 配置在输入框里难以编辑
|
||||
fieldList.value = (res.data ?? []).map((f: DeviceFieldVO) => ({ ...f, options: parseFieldOptions(f.options).join(',') }));
|
||||
};
|
||||
|
||||
const addFieldRow = () => {
|
||||
@ -288,10 +384,37 @@ const removeFieldRow = (index: number) => {
|
||||
fieldList.value.splice(index, 1);
|
||||
};
|
||||
|
||||
// ---------------- 字段回收站 ----------------
|
||||
const loadDeletedFields = async () => {
|
||||
const res = await listDeletedFields(fieldDrawer.typeId);
|
||||
fieldRecycle.list = res.data ?? [];
|
||||
};
|
||||
|
||||
const openFieldRecycle = async () => {
|
||||
fieldRecycle.visible = true;
|
||||
await loadDeletedFields();
|
||||
};
|
||||
|
||||
const handleRestoreField = async (row: DeviceFieldVO) => {
|
||||
if (!row.id) return;
|
||||
await proxy?.$modal.confirm(`是否恢复字段"${row.fieldLabel}"?`);
|
||||
await restoreField(row.id);
|
||||
proxy?.$modal.msgSuccess('恢复成功');
|
||||
fieldRecycle.list = fieldRecycle.list.filter((f) => String(f.id) !== String(row.id));
|
||||
if (!fieldList.value.some((f) => String(f.id) === String(row.id))) {
|
||||
fieldList.value.push({ ...row, status: '0', sort: fieldList.value.length });
|
||||
}
|
||||
};
|
||||
|
||||
const saveFields = async () => {
|
||||
for (const f of fieldList.value) {
|
||||
if (!f.fieldKey || !f.fieldLabel) {
|
||||
proxy?.$modal.msgWarning('存在未填写完整字段键/标签的字段行');
|
||||
f.fieldLabel = f.fieldLabel?.trim();
|
||||
if (!f.fieldLabel) {
|
||||
proxy?.$modal.msgWarning('存在未填写显示标签的字段行');
|
||||
return;
|
||||
}
|
||||
if (needOptions(f.fieldType) && parseFieldOptions(f.options).length === 0) {
|
||||
proxy?.$modal.msgWarning(`字段"${f.fieldLabel}"为选择类,请填写选项(逗号分隔)`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -307,6 +430,7 @@ const saveFields = async () => {
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
loadCustomIcons();
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -61,6 +61,7 @@
|
||||
<div class="detail-body">
|
||||
<div class="detail-tag"><span class="order-card__status" :class="statusClass(detail.status)">{{ statusLabel(detail.status) }}</span></div>
|
||||
<div class="detail-row"><label>工单号</label><span>{{ detail.orderCode }}</span></div>
|
||||
<div class="detail-row"><label>标题</label><span>{{ detail.title || '-' }}</span></div>
|
||||
<div class="detail-row" v-if="detail.deviceName"><label>设备</label><span>{{ detail.deviceName }}<template v-if="detail.deviceCode">({{ detail.deviceCode }})</template></span></div>
|
||||
<div class="detail-row" v-if="detail.orderType"><label>类型</label><span>{{ typeLabel(detail.orderType) }}</span></div>
|
||||
<div class="detail-row" v-if="detail.description"><label>问题描述</label><span>{{ detail.description }}</span></div>
|
||||
@ -167,9 +168,12 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="关联设备(可空)">
|
||||
<el-select v-model="createForm.deviceId" filterable remote clearable :remote-method="loadDevices" placeholder="输入名称搜索设备" style="width: 100%">
|
||||
<el-option v-for="d in deviceOpts" :key="d.id" :label="`${d.deviceName}(${d.deviceCode})`" :value="d.id" />
|
||||
</el-select>
|
||||
<div class="device-picker">
|
||||
<el-select v-model="createForm.deviceId" filterable remote clearable :remote-method="loadDevices" placeholder="输入名称搜索设备" style="flex: 1">
|
||||
<el-option v-for="d in deviceOpts" :key="d.id" :label="`${d.deviceName}(${d.deviceCode})`" :value="d.id" />
|
||||
</el-select>
|
||||
<el-button icon="Camera" @click="scanDevice">扫码</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="工单标题" required>
|
||||
<el-input v-model="createForm.title" placeholder="请输入工单标题" />
|
||||
@ -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<string, string> = {};
|
||||
((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 () => {
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.device-picker {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.h5-order {
|
||||
min-height: 100vh;
|
||||
background: #f4f6fa;
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<span class="sb-screen__title">交管设备资产一张图</span>
|
||||
<span class="sb-screen__title">设备资产一张图</span>
|
||||
</header>
|
||||
|
||||
<div class="sb-screen__body">
|
||||
@ -93,6 +93,7 @@ import { getOverview, countByType, deviceStatus } from '@/api/sbgl/stats';
|
||||
import { DeviceVO } from '@/api/sbgl/device/types';
|
||||
import { DeviceTypeVO } from '@/api/sbgl/devicetype/types';
|
||||
import { StatItemVO, OverviewVO } from '@/api/sbgl/stats';
|
||||
import { formatFieldValue } from '../devicetype/fieldTypes';
|
||||
|
||||
const { proxy } = getCurrentInstance() as any;
|
||||
const { sb_device_status } = toRefs<any>(proxy?.useDict('sb_device_status'));
|
||||
@ -106,8 +107,8 @@ const visibleTypes = ref<string[]>([]);
|
||||
/** 业务图层面板是否收起 */
|
||||
const layersCollapsed = ref(true);
|
||||
const selected = ref<DeviceVO | null>(null);
|
||||
/** 各类型启用的属性字段配置:typeId -> fieldKey -> label */
|
||||
const fieldLabelMap = ref<Record<string, Record<string, string>>>({});
|
||||
/** 各类型启用的属性字段配置:typeId -> fieldKey -> { label, fieldType } */
|
||||
const fieldMetaMap = ref<Record<string, Record<string, { label: string; fieldType: string }>>>({});
|
||||
|
||||
const statusText = (s?: string) => {
|
||||
if (s === null || s === undefined || s === '') return '-';
|
||||
@ -121,10 +122,13 @@ const statusClass = (s?: string) => (String(s) === '2' ? 'warn' : String(s) ===
|
||||
const attrRows = computed(() => {
|
||||
if (!selected.value) return [];
|
||||
const attrs = (typeof selected.value.attrs === 'string' ? JSON.parse(selected.value.attrs) : selected.value.attrs) ?? {};
|
||||
const labels = fieldLabelMap.value[String(selected.value.typeId)] ?? {};
|
||||
const metas = fieldMetaMap.value[String(selected.value.typeId)] ?? {};
|
||||
return Object.entries(attrs)
|
||||
.filter(([, v]) => v !== null && v !== undefined && v !== '')
|
||||
.map(([k, v]) => ({ label: labels[k] ?? k, value: Array.isArray(v) ? v.join('、') : String(v) }));
|
||||
.filter(([, v]) => v !== null && v !== undefined && v !== '' && !(Array.isArray(v) && v.length === 0))
|
||||
.map(([k, v]) => {
|
||||
const meta = metas[k];
|
||||
return { label: meta?.label ?? k, value: formatFieldValue(meta?.fieldType, v) };
|
||||
});
|
||||
});
|
||||
|
||||
const esc = (s: unknown) =>
|
||||
@ -135,11 +139,14 @@ const visiblePoints = computed(() =>
|
||||
.filter((d) => visibleTypes.value.includes(String(d.typeId)) && d.lng && d.lat)
|
||||
.map((d) => {
|
||||
const attrs = (typeof d.attrs === 'string' ? JSON.parse(d.attrs) : d.attrs) ?? {};
|
||||
const labels = fieldLabelMap.value[String(d.typeId)] ?? {};
|
||||
const metas = fieldMetaMap.value[String(d.typeId)] ?? {};
|
||||
const attrRows = Object.entries(attrs)
|
||||
.filter(([, v]) => v !== null && v !== undefined && v !== '')
|
||||
.filter(([, v]) => v !== null && v !== undefined && v !== '' && !(Array.isArray(v) && v.length === 0))
|
||||
.slice(0, 5)
|
||||
.map(([k, v]) => `<div><b>${esc(labels[k] ?? k)}:</b>${esc(Array.isArray(v) ? v.join('、') : v)}</div>`)
|
||||
.map(([k, v]) => {
|
||||
const meta = metas[k];
|
||||
return `<div><b>${esc(meta?.label ?? k)}:</b>${esc(formatFieldValue(meta?.fieldType, v))}</div>`;
|
||||
})
|
||||
.join('');
|
||||
const popupHtml = `
|
||||
<div style="font-weight:600;font-size:14px;margin-bottom:2px;">${esc(d.deviceName)}</div>
|
||||
@ -174,15 +181,15 @@ onMounted(async () => {
|
||||
typeOptions.value.map(async (t) => {
|
||||
try {
|
||||
const res = await listEnabledFields(t.id as string | number);
|
||||
const map: Record<string, string> = {};
|
||||
(res.data ?? []).forEach((f: any) => (map[f.fieldKey] = f.fieldLabel));
|
||||
const map: Record<string, { label: string; fieldType: string }> = {};
|
||||
(res.data ?? []).forEach((f: any) => (map[f.fieldKey] = { label: f.fieldLabel, fieldType: f.fieldType }));
|
||||
return [String(t.id), map] as const;
|
||||
} catch {
|
||||
return [String(t.id), {}] as const;
|
||||
}
|
||||
})
|
||||
);
|
||||
fieldLabelMap.value = Object.fromEntries(labelEntries);
|
||||
fieldMetaMap.value = Object.fromEntries(labelEntries);
|
||||
|
||||
const res = await listMapDevice({});
|
||||
deviceList.value = (res.data ?? []).map((d: any) => ({
|
||||
|
||||
@ -212,6 +212,7 @@
|
||||
<template v-if="detail">
|
||||
<el-descriptions :column="2" border size="small" class="mb-3">
|
||||
<el-descriptions-item label="工单编号">{{ detail.orderCode }}</el-descriptions-item>
|
||||
<el-descriptions-item label="标题">{{ detail.title || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="类型">
|
||||
<dict-tag :options="sb_order_type" :value="detail.orderType" />
|
||||
</el-descriptions-item>
|
||||
@ -219,7 +220,7 @@
|
||||
<dict-tag :options="sb_order_status" :value="detail.status" />
|
||||
<el-tag v-if="detail.timeoutFlag === 1" type="danger" size="small" class="ml-1">超时</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="关联设备">{{ detail.deviceName || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="关联设备" :span="2">{{ detail.deviceName || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="发起人">{{ detail.reportName }}</el-descriptions-item>
|
||||
<el-descriptions-item label="发起时间">{{ proxy?.parseTime(detail.reportTime) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="处理时限">{{ proxy?.parseTime(detail.deadline) }}</el-descriptions-item>
|
||||
@ -253,7 +254,7 @@
|
||||
|
||||
<script setup name="WorkOrder" lang="ts">
|
||||
import ImagePreview from '@/components/ImagePreview/index.vue';
|
||||
import { listByIds } from '@/api/system/oss';
|
||||
import { listBusinessOss } from '@/api/sbgl/common';
|
||||
import { listOrder, getOrder, submitOrder, updateOrder, dispatchOrder, handleOrder, verifyOrder, closeOrder, urgeOrder, listOrderRecords } from '@/api/sbgl/workorder';
|
||||
import { WorkOrderVO, WorkOrderQuery, WorkOrderForm, OrderRecordVO } from '@/api/sbgl/workorder/types';
|
||||
import { listDevice, getDeviceOptions } from '@/api/sbgl/device';
|
||||
@ -561,7 +562,7 @@ const openDetail = async (row: WorkOrderVO) => {
|
||||
try {
|
||||
const allIds = [...new Set(records.value.flatMap((r: any) => (r.images ? r.images.split(',') : [])))].filter(Boolean).join(',');
|
||||
if (allIds) {
|
||||
const ossRes = await listByIds(allIds);
|
||||
const ossRes = await listBusinessOss(allIds);
|
||||
const urlMap: Record<string, string> = {};
|
||||
(ossRes.data ?? []).forEach((o: any) => (urlMap[o.ossId] = o.url));
|
||||
records.value.forEach((r: any) => {
|
||||
@ -576,10 +577,24 @@ const openDetail = async (row: WorkOrderVO) => {
|
||||
detailVisible.value = true;
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
getList();
|
||||
/** 设备类型下拉:keep-alive 页面再次进入时需刷新,保证新增类型立即可见 */
|
||||
const loadTypeOptions = async () => {
|
||||
const res = await listTypeOptions();
|
||||
typeOptions.value = res.data ?? [];
|
||||
};
|
||||
|
||||
let typeOptionsActivated = false;
|
||||
|
||||
onMounted(async () => {
|
||||
getList();
|
||||
await loadTypeOptions();
|
||||
});
|
||||
|
||||
onActivated(() => {
|
||||
if (typeOptionsActivated) {
|
||||
loadTypeOptions();
|
||||
}
|
||||
typeOptionsActivated = true;
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<div class="p-2">
|
||||
<el-row :gutter="20">
|
||||
<!-- 部门树 -->
|
||||
<el-col :lg="4" :xs="24" style="">
|
||||
<el-col :span="4" :xs="24">
|
||||
<el-card shadow="hover">
|
||||
<el-input v-model="deptName" placeholder="请输入部门名称" prefix-icon="Search" clearable />
|
||||
<el-tree
|
||||
@ -19,7 +19,7 @@
|
||||
/>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :lg="20" :xs="24">
|
||||
<el-col :span="20" :xs="24">
|
||||
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||
<div v-show="showSearch" class="mb-[10px]">
|
||||
<el-card shadow="hover">
|
||||
|
||||
@ -151,7 +151,7 @@
|
||||
</el-dialog>
|
||||
|
||||
<!-- 分配角色数据权限对话框 -->
|
||||
<el-dialog v-model="openDataScope" :title="dialog.title" width="500px" append-to-body>
|
||||
<el-dialog v-model="openDataScope" :title="dialog.title" width="640px" append-to-body>
|
||||
<el-form ref="dataScopeRef" :model="form" label-width="80px">
|
||||
<el-form-item label="角色名称">
|
||||
<el-input v-model="form.roleName" :disabled="true" />
|
||||
@ -180,6 +180,23 @@
|
||||
:props="{ label: 'label', children: 'children' } as any"
|
||||
></el-tree>
|
||||
</el-form-item>
|
||||
<el-divider content-position="left">设备资产模块数据范围</el-divider>
|
||||
<el-form-item label="模块范围">
|
||||
<el-table :data="moduleScopes" size="small" border style="width: 100%">
|
||||
<el-table-column label="模块" prop="label" width="110" />
|
||||
<el-table-column label="数据范围">
|
||||
<template #default="scope">
|
||||
<el-select v-model="scope.row.scopeType" placeholder="沿用角色数据权限" style="width: 100%">
|
||||
<el-option label="沿用角色数据权限(默认)" value="" />
|
||||
<el-option v-for="item in moduleScopeOptions" :key="item.value" :label="item.label" :value="item.value" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="text-gray-400 mt-1" style="font-size: 12px">
|
||||
模块配置仅作用于设备资产模块;未配置时沿用上方角色数据权限。本辖区按用户所属部门树计算(当前与“本部门及下级”一致);本维护单位按维护单位名称或该单位下处理人匹配工单。
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
@ -196,6 +213,7 @@ import { addRole, changeRoleStatus, dataScope, delRole, getRole, listRole, updat
|
||||
import { roleMenuTreeselect, treeselect as menuTreeselect } from '@/api/system/menu/index';
|
||||
import { RoleVO, RoleForm, RoleQuery, DeptTreeOption } from '@/api/system/role/types';
|
||||
import { MenuTreeOption, RoleMenuTree } from '@/api/system/menu/types';
|
||||
import { getRoleScopes, saveRoleScopes } from '@/api/sbgl/roleScope';
|
||||
|
||||
const router = useRouter();
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
@ -227,6 +245,23 @@ const dataScopeOptions = ref([
|
||||
{ value: '6', label: '部门及以下或本人数据权限' }
|
||||
]);
|
||||
|
||||
/** 设备资产模块数据范围选项 */
|
||||
const moduleScopeOptions = [
|
||||
{ value: 'ALL', label: '全部' },
|
||||
{ value: 'SELF', label: '本人' },
|
||||
{ value: 'DEPT', label: '本部门' },
|
||||
{ value: 'DEPT_AND_CHILD', label: '本部门及下级' },
|
||||
{ value: 'JURISDICTION', label: '本辖区' },
|
||||
{ value: 'MAINTENANCE', label: '本维护单位' }
|
||||
];
|
||||
|
||||
const defaultModuleScopes = () => [
|
||||
{ module: 'device', label: '设备台账', scopeType: '' },
|
||||
{ module: 'order', label: '运维工单', scopeType: '' },
|
||||
{ module: 'report', label: '统计分析', scopeType: '' }
|
||||
];
|
||||
const moduleScopes = ref(defaultModuleScopes());
|
||||
|
||||
const queryFormRef = ref<ElFormInstance>();
|
||||
const roleFormRef = ref<ElFormInstance>();
|
||||
const dataScopeRef = ref<ElFormInstance>();
|
||||
@ -474,6 +509,16 @@ const handleDataScope = async (row: RoleVO) => {
|
||||
const response = await getRole(row.roleId);
|
||||
Object.assign(form.value, response.data);
|
||||
const res = await getRoleDeptTreeSelect(row.roleId);
|
||||
moduleScopes.value = defaultModuleScopes();
|
||||
try {
|
||||
const scopeRes = await getRoleScopes(row.roleId);
|
||||
const scopeMap = new Map(
|
||||
(scopeRes.data ?? []).map((item: any) => [item.module, item.scopeType ?? ''] as const)
|
||||
);
|
||||
moduleScopes.value = defaultModuleScopes().map((item) => ({ ...item, scopeType: (scopeMap.get(item.module) as string) ?? '' }));
|
||||
} catch {
|
||||
// 模块范围加载失败时保持默认“沿用角色数据权限”
|
||||
}
|
||||
openDataScope.value = true;
|
||||
dialog.title = '分配数据权限';
|
||||
await nextTick(() => {
|
||||
@ -485,6 +530,10 @@ const submitDataScope = async () => {
|
||||
if (form.value.roleId) {
|
||||
form.value.deptIds = getDeptAllCheckedKeys();
|
||||
await dataScope(form.value);
|
||||
await saveRoleScopes(
|
||||
form.value.roleId,
|
||||
moduleScopes.value.map((item) => ({ module: item.module, scopeType: item.scopeType }))
|
||||
);
|
||||
proxy?.$modal.msgSuccess('修改成功');
|
||||
openDataScope.value = false;
|
||||
getList();
|
||||
@ -494,6 +543,7 @@ const submitDataScope = async () => {
|
||||
const cancelDataScope = () => {
|
||||
dataScopeRef.value?.resetFields();
|
||||
form.value = { ...initForm };
|
||||
moduleScopes.value = defaultModuleScopes();
|
||||
openDataScope.value = false;
|
||||
};
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<div class="p-2">
|
||||
<el-row :gutter="20">
|
||||
<!-- 部门树 -->
|
||||
<el-col :lg="4" :xs="24" style="">
|
||||
<el-col :span="4" :xs="24">
|
||||
<el-card shadow="hover">
|
||||
<el-input v-model="deptName" placeholder="请输入部门名称" prefix-icon="Search" clearable />
|
||||
<el-tree
|
||||
@ -19,7 +19,7 @@
|
||||
/>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :lg="20" :xs="24">
|
||||
<el-col :span="20" :xs="24">
|
||||
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||
<div v-show="showSearch" class="mb-[10px]">
|
||||
<el-card shadow="hover">
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<div class="p-2">
|
||||
<el-row :gutter="20">
|
||||
<!-- 流程分类树 -->
|
||||
<el-col :lg="4" :xs="24" style="">
|
||||
<el-col :span="4" :xs="24">
|
||||
<el-card shadow="hover">
|
||||
<el-input v-model="categoryName" placeholder="请输入流程分类名" prefix-icon="Search" clearable />
|
||||
<el-tree
|
||||
@ -19,7 +19,7 @@
|
||||
></el-tree>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :lg="20" :xs="24">
|
||||
<el-col :span="20" :xs="24">
|
||||
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||
<div v-show="showSearch" class="mb-[10px]">
|
||||
<el-card shadow="hover">
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<div class="p-2">
|
||||
<el-row :gutter="20">
|
||||
<!-- 流程分类树 -->
|
||||
<el-col :lg="4" :xs="24" style="">
|
||||
<el-col :span="4" :xs="24">
|
||||
<el-card shadow="hover">
|
||||
<el-input v-model="categoryName" placeholder="请输入流程分类名" prefix-icon="Search" clearable />
|
||||
<el-tree
|
||||
@ -19,7 +19,7 @@
|
||||
></el-tree>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :lg="20" :xs="24">
|
||||
<el-col :span="20" :xs="24">
|
||||
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||
<div v-show="showSearch" class="mb-[10px]">
|
||||
<el-card shadow="hover">
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<div class="p-2">
|
||||
<el-row :gutter="20">
|
||||
<!-- 流程分类树 -->
|
||||
<el-col :lg="4" :xs="24" style="">
|
||||
<el-col :span="4" :xs="24">
|
||||
<el-card shadow="hover">
|
||||
<el-input v-model="categoryName" placeholder="请输入流程分类名" prefix-icon="Search" clearable />
|
||||
<el-tree
|
||||
@ -19,7 +19,7 @@
|
||||
></el-tree>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :lg="20" :xs="24">
|
||||
<el-col :span="20" :xs="24">
|
||||
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||
<div v-show="showSearch" class="mb-[10px]">
|
||||
<el-card shadow="hover">
|
||||
|
||||