Commit 02402718 by 李伟康

refactor(dailyNewspaper): 优化模块逻辑与交互,修复兼容问题

- 重构日报详情检查逻辑,优化数据更新提示判断
- 修复编辑表单隐藏时未同步清空绑定字段的问题,优化多选择器空值处理
- 重写APP端图片转base64方法,解决Android 10+存储兼容问题
- 优化弹窗组件校验逻辑,新增必填项提示
- 统一全模块代码格式与语法风格
1 parent 88fbeec1
......@@ -160,7 +160,10 @@ export default {
})
let show = func(...value)
item.show = show
if (!item.show && item.value) item.value = null
if (!item.show && item.value) {
item.value = null
item[item.key] = null
}
return show
} else {
item.show = true
......@@ -198,7 +201,7 @@ export default {
* 7: 多选
*/
if (popupType == 6 || popupType == 5) {
this.$set(this.data[itemIndex], 'value', chooseContent)
this.$set(this.data[itemIndex], 'value', chooseContent || '')
} else if (popupType == 3) {
const { vehicleBrandName, vehicleSubBrandName, vehicleSeriesName, vehicleShapeName } = chooseContent
let carName = `${vehicleBrandName}-${vehicleSubBrandName}-${vehicleSeriesName}`
......@@ -207,9 +210,9 @@ export default {
this.$set(this.data[itemIndex], this.data[itemIndex].key, chooseContent)
} else if (popupType == 4) {
this.$set(this.data[itemIndex], 'value', chooseContent.orderCode)
this.$set(this.data[itemIndex], 'value', chooseContent?.orderCode || '')
let completeFun = this.data[itemIndex].completeFun
if (completeFun) {
if (completeFun && chooseContent) {
let { keys, resultKeys } = completeFun
keys.map((key, index) => {
let ind = this.data.findIndex(i => i.key == key),
......@@ -219,13 +222,13 @@ export default {
}
} else if (popupType == 7) {
let label = chooseContent.map(item => item.label).join('/'),
value = chooseContent.map(item => item.value)
let label = chooseContent?.map(item => item.label).join('/') || '',
value = chooseContent?.map(item => item.value) || []
this.$set(this.data[itemIndex], 'value', label)
this.$set(this.data[itemIndex], this.data[itemIndex].key, value)
} else {
this.$set(this.data[itemIndex], 'value', chooseContent.staffName)
this.$set(this.data[itemIndex], this.data[itemIndex].key, chooseContent.uuid)
this.$set(this.data[itemIndex], 'value', chooseContent?.staffName || '')
this.$set(this.data[itemIndex], this.data[itemIndex].key, chooseContent?.uuid || '')
}
let clearkeys = this.data[itemIndex].clearkeys
if (clearkeys) {
......
......@@ -194,30 +194,100 @@ export default {
},
getBase64FromImagePath(imagePath) {
return new Promise((resolve, reject) => {
// APP 平台使用 plus.io 来读取文件
plus.io.resolveLocalFileSystemURL(imagePath, (entry) => {
entry.file((file) => {
const reader = new plus.io.FileReader()
reader.onloadend = (e) => {
const base64 = e.target.result
let prefix = 'data:image/png;base64,'
if (imagePath.toLowerCase().endsWith('.jpg') || imagePath.toLowerCase().endsWith('.jpeg')) {
prefix = 'data:image/jpeg;base64,'
} else if (imagePath.toLowerCase().endsWith('.gif')) {
prefix = 'data:image/gif;base64,'
}
resolve(prefix + base64.split(',')[1]) // 去掉 data URL 前缀,因为我们自己添加
// #ifdef APP-PLUS
// 1. 优先使用 plus.nativeObj.Bitmap,它专门处理图片且对 Android 10+ 路径兼容性较好
const bitmap = new plus.nativeObj.Bitmap('scan_vin_' + Date.now());
bitmap.load(imagePath, () => {
const base64 = bitmap.toBase64Data();
bitmap.clear();
// Bitmap.toBase64Data() 返回的已经是完整的 data URL
resolve(base64);
}, (err) => {
bitmap.clear();
console.error('Bitmap 加载失败,尝试 plus.io:', err);
// 2. 备选方案:plus.io
this.plusReadBase64(imagePath, resolve, (err2) => {
console.error('plus.io 读取失败,尝试原生 Java 读取:', err2);
// 3. 终极方案:针对 Android 10+ 的原生 Java 读取 (绕过 Scoped Storage 限制)
if (plus.os.name === 'Android') {
this.readBase64ByAndroid(imagePath).then(base64 => {
let prefix = 'data:image/png;base64,'
const lowerPath = imagePath.toLowerCase()
if (lowerPath.endsWith('.jpg') || lowerPath.endsWith('.jpeg')) {
prefix = 'data:image/jpeg;base64,'
} else if (lowerPath.endsWith('.gif')) {
prefix = 'data:image/gif;base64,'
}
resolve(prefix + base64);
}).catch(err3 => {
reject(err3);
});
} else {
reject(err2);
}
reader.onerror = (err) => {
reject(err)
});
});
// #endif
// #ifndef APP-PLUS
reject(new Error('当前环境不支持该操作'))
// #endif
})
},
readBase64ByAndroid(absPath) {
return new Promise((resolve, reject) => {
try {
// 清洗路径
let path = absPath.replace(/^file:\/\//, '');
const File = plus.android.importClass('java.io.File');
const FileInputStream = plus.android.importClass('java.io.FileInputStream');
const Base64 = plus.android.importClass('android.util.Base64');
const file = new File(path);
if (!file.exists()) {
return reject('文件不存在: ' + path);
}
const fis = new FileInputStream(file);
const length = file.length();
const buffer = plus.android.newObject('byte[]', length);
fis.read(buffer);
fis.close();
// Base64.NO_WRAP 避免换行符
const base64 = Base64.encodeToString(buffer, 2);
resolve(base64);
} catch (e) {
reject('原生读取异常: ' + e);
}
});
},
plusReadBase64(imagePath, resolve, reject) {
// 兼容性回退:尝试使用 plus.io
plus.io.resolveLocalFileSystemURL(imagePath, (entry) => {
entry.file((file) => {
const reader = new plus.io.FileReader()
reader.onloadend = (e) => {
const base64 = e.target.result
let prefix = 'data:image/png;base64,'
if (imagePath.toLowerCase().endsWith('.jpg') || imagePath.toLowerCase().endsWith('.jpeg')) {
prefix = 'data:image/jpeg;base64,'
} else if (imagePath.toLowerCase().endsWith('.gif')) {
prefix = 'data:image/gif;base64,'
}
reader.readAsDataURL(file)
}, (err) => {
resolve(prefix + base64.split(',')[1])
}
reader.onerror = (err) => {
reject(err)
})
}
reader.readAsDataURL(file)
}, (err) => {
reject(err)
})
}, (err) => {
reject(err)
})
},
async orcRecogintion(imgBase64) {
......
......@@ -228,7 +228,7 @@ export default {
.filter(item => {
if (item.type == 'subform' && item.children.length) {
item.children[0] = item.children[0].filter(child => {
if(child.filterBrandId && child.filterBrandId.length) {
if (child.filterBrandId && child.filterBrandId.length) {
return !isSubset(child.filterBrandId, CAR_BRAND_ID)
} else {
return child.brandId?.length ? hasCommonElement(child.brandId, CAR_BRAND_ID) : true
......@@ -333,9 +333,8 @@ export default {
this.$refs.notice.open()
},
async checkReportDetail(data) {
let flag = this.dailyReportRecordId
if (!flag) flag = await this.getReportDetail(true)
if (flag) {
let new_daily_report_record_id = await this.getReportDetail(true)
if (new_daily_report_record_id != this.dailyReportRecordId) {
this.openNotice(
{
title: '数据已被他人更新',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!