Commit 02402718 by 李伟康

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

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