feat:设备管理

This commit is contained in:
houjunxiang
2026-03-09 17:53:33 +08:00
parent 9c88c45d66
commit 6004f6c032
19 changed files with 1196 additions and 1057 deletions

View File

@@ -41,7 +41,7 @@ const imgs = ref([])
const uploadConfig = reactive({
baseURL: getBaseUrl(),
imgBaseURL: getImgBaseUrl(),
header: { 'X-Access-Token': uni.getStorageSync('token') }
header: { Authorization: 'Bearer ' + uni.getStorageSync('token') }
})
// 同步外部值到组件
@@ -50,10 +50,12 @@ watch(
newVal => {
if (!newVal) return (fileList.value = [])
const urls = Array.isArray(newVal) ? newVal : newVal.split(',')
imgs.value = urls
imgs.value = urls.map(url => url.previewUrl)
fileList.value = urls.map(url => ({
url: uploadConfig.imgBaseURL + url,
url: url.url,
status: 'success',
name: url.name,
id: url.id,
message: ''
}))
},
@@ -82,10 +84,13 @@ const afterRead = async event => {
for (let i = 0; i < files.length; i++) {
const result = await uploadFile(files[i])
const index = initialLength + i
console.log(files[i])
fileList.value[index] = {
...files[i],
status: 'success',
url: uploadConfig.imgBaseURL + result.message
url: result.url,
name: result.name,
id: result.id
}
}
} catch (error) {
@@ -100,14 +105,19 @@ const afterRead = async event => {
const uploadFile = file => {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: `${uploadConfig.baseURL}/sys/common/upload`,
url: `${uploadConfig.baseURL}/infra/file/upload-with-return`,
filePath: file.url,
name: 'file',
header: uploadConfig.header,
formData: { biz: 'lims-device' },
formData: { encrypt: false },
success: res => {
if (res.statusCode === 200) {
resolve(JSON.parse(res.data))
let result = JSON.parse(res.data)
if (result.code === 0) {
resolve(result.data)
} else {
reject(new Error(result.msg))
}
} else {
reject(new Error(res.data))
}
@@ -125,7 +135,7 @@ const formatValue = fileList => {
: fileList.map(item => item.url.slice(baseUrlLength))
}
const updateParent = fileList => {
emit('update:modelValue', formatValue(fileList))
emit('update:modelValue', fileList)
}
</script>