|
@@ -161,11 +161,10 @@ import {
|
|
|
testByIP,
|
|
testByIP,
|
|
|
getAttrByLocal
|
|
getAttrByLocal
|
|
|
} from '@/service/api'
|
|
} from '@/service/api'
|
|
|
-import { getEnvBaseUrl, redirectToUpload, reLaunchToHome } from '@/utils'
|
|
|
|
|
-import { useUserStore } from '@/store'
|
|
|
|
|
|
|
+import { getEnvBaseUrl, redirectToUpload, reLaunchToHome, logManager } from '@/utils'
|
|
|
|
|
|
|
|
-const userStore = useUserStore()
|
|
|
|
|
-const token = userStore.token
|
|
|
|
|
|
|
+const deviceInfo = uni.getDeviceInfo() // 更多系统信息用 getSystemInfoSync
|
|
|
|
|
+const fs = wx.getFileSystemManager();
|
|
|
const baseUrl = getEnvBaseUrl()
|
|
const baseUrl = getEnvBaseUrl()
|
|
|
const toast = useToast()
|
|
const toast = useToast()
|
|
|
const message = useMessage()
|
|
const message = useMessage()
|
|
@@ -239,7 +238,8 @@ function checkUserHub() {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- }).catch(() => {
|
|
|
|
|
|
|
+ }).catch((err) => {
|
|
|
|
|
+ console.log('getUserHubPage catch: ', err);
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -250,7 +250,9 @@ function checkIP(ip, userHubId) {
|
|
|
userHubList.value.find(i => i.id == userHubId).isIntranet = true
|
|
userHubList.value.find(i => i.id == userHubId).isIntranet = true
|
|
|
updateShowName()
|
|
updateShowName()
|
|
|
}
|
|
}
|
|
|
- }).catch(() => {})
|
|
|
|
|
|
|
+ }).catch((err) => {
|
|
|
|
|
+ console.log('checkIP catch: ', err);
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 更新打印机展示名称
|
|
// 更新打印机展示名称
|
|
@@ -276,7 +278,9 @@ function getPrinterList() {
|
|
|
checkUserHub()
|
|
checkUserHub()
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
- .catch((e) => {})
|
|
|
|
|
|
|
+ .catch((err) => {
|
|
|
|
|
+ console.log('getUserHubPrints catch: ', err);
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 处理更换打印机, 获取配置参数
|
|
// 处理更换打印机, 获取配置参数
|
|
@@ -328,7 +332,8 @@ function handlePrinterChange(item: any) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
- .catch((e) => {
|
|
|
|
|
|
|
+ .catch((err) => {
|
|
|
|
|
+ console.log('getFn catch: ', err);
|
|
|
})
|
|
})
|
|
|
.finally(() => {})
|
|
.finally(() => {})
|
|
|
}
|
|
}
|
|
@@ -348,6 +353,23 @@ function getFileIcon(fileName) {
|
|
|
return srcMap[getFileType(fileName)] || otherSrc
|
|
return srcMap[getFileType(fileName)] || otherSrc
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 复制文件并重命名
|
|
|
|
|
+function copyAndRenamed(fileName, filePath) {
|
|
|
|
|
+ // const targetPath = `${uni.env.USER_DATA_PATH}/${fileName}`
|
|
|
|
|
+ // // 写入文件
|
|
|
|
|
+ // fs.writeFile({
|
|
|
|
|
+ // filePath: targetPath,
|
|
|
|
|
+ // data: fileData,
|
|
|
|
|
+ // encoding: 'binary', // 与 readFile 的编码一致
|
|
|
|
|
+ // success() {
|
|
|
|
|
+ // console.log('文件保存成功:', targetPath);
|
|
|
|
|
+ // },
|
|
|
|
|
+ // fail(err) {
|
|
|
|
|
+ // console.error('写入失败:', err);
|
|
|
|
|
+ // }
|
|
|
|
|
+ // });
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// 处理选择文件
|
|
// 处理选择文件
|
|
|
function selectFile() {
|
|
function selectFile() {
|
|
|
switch(accept.value) {
|
|
switch(accept.value) {
|
|
@@ -359,7 +381,10 @@ function selectFile() {
|
|
|
console.log('chooseMessageFile IMG res: ', res);
|
|
console.log('chooseMessageFile IMG res: ', res);
|
|
|
if (res.errMsg == "chooseMessageFile:ok") {
|
|
if (res.errMsg == "chooseMessageFile:ok") {
|
|
|
let failList = []
|
|
let failList = []
|
|
|
|
|
+
|
|
|
res.tempFiles.forEach(item => {
|
|
res.tempFiles.forEach(item => {
|
|
|
|
|
+ // 使用 getFileSystemManager 复制一个文件到目标路径
|
|
|
|
|
+ let copyFile = copyAndRenamed(item.name, item.path)
|
|
|
if (item.size > maxSize || !allowType.includes(getFileType(item.name))) {
|
|
if (item.size > maxSize || !allowType.includes(getFileType(item.name))) {
|
|
|
failList.push(item)
|
|
failList.push(item)
|
|
|
} else {
|
|
} else {
|
|
@@ -375,8 +400,27 @@ function selectFile() {
|
|
|
toast.warning("选择微信图片异常, 请重试")
|
|
toast.warning("选择微信图片异常, 请重试")
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- fail () {
|
|
|
|
|
- toast.warning("选择微信图片失败, 请重试")
|
|
|
|
|
|
|
+ fail (err) {
|
|
|
|
|
+ console.log('chooseMessageFile IMG err: ', err);
|
|
|
|
|
+ let tips = "选择微信图片失败, 请重试"
|
|
|
|
|
+ switch (err.errMsg) {
|
|
|
|
|
+ case "chooseMessageFile:fail cancel":
|
|
|
|
|
+ tips = "已取消选择微信图片"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseMessageFile:fail auth deny":
|
|
|
|
|
+ case "chooseMessageFile:fail permission denied":
|
|
|
|
|
+ tips = "未授权文件访问权限,无法访问文件"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseMessageFile:fail file not found":
|
|
|
|
|
+ tips = "选择的文件已被删除或移动"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseMessageFile:fail system error":
|
|
|
|
|
+ tips = "微信内部错误,请检查微信版本、重启小程序或设备"
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ logManager.error("未处理的选择微信图片异常 errMsg::", JSON.stringify(err.errMsg))
|
|
|
|
|
+ }
|
|
|
|
|
+ toast.warning(tips)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
break;
|
|
break;
|
|
@@ -405,8 +449,27 @@ function selectFile() {
|
|
|
toast.warning("选择微信文件异常, 请重试")
|
|
toast.warning("选择微信文件异常, 请重试")
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- fail () {
|
|
|
|
|
- toast.warning("选择微信文件失败, 请重试")
|
|
|
|
|
|
|
+ fail (err) {
|
|
|
|
|
+ console.log('chooseMessageFile FILE err: ', err);
|
|
|
|
|
+ let tips = "选择微信文件失败, 请重试"
|
|
|
|
|
+ switch (err.errMsg) {
|
|
|
|
|
+ case "chooseMessageFile:fail cancel":
|
|
|
|
|
+ tips = "已取消选择微信文件"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseMessageFile:fail auth deny":
|
|
|
|
|
+ case "chooseMessageFile:fail permission denied":
|
|
|
|
|
+ tips = "未授权文件访问权限,无法访问文件"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseMessageFile:fail file not found":
|
|
|
|
|
+ tips = "选择的文件已被删除或移动"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseMessageFile:fail system error":
|
|
|
|
|
+ tips = "微信内部错误,请检查微信版本、重启小程序或设备"
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ logManager.error("未处理的选择微信文件失败 errMsg::", JSON.stringify(err.errMsg))
|
|
|
|
|
+ }
|
|
|
|
|
+ toast.warning(tips)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
break;
|
|
break;
|
|
@@ -437,8 +500,30 @@ function selectFile() {
|
|
|
toast.warning("选择相册图片异常, 请重试")
|
|
toast.warning("选择相册图片异常, 请重试")
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- fail () {
|
|
|
|
|
- toast.warning("选择相册图片失败, 请重试")
|
|
|
|
|
|
|
+ fail (err) {
|
|
|
|
|
+ console.log('chooseImage err: ', err);
|
|
|
|
|
+ let tips = ['windows', 'mac'].includes(deviceInfo.platform) ? "已取消选择相册图片" : "选择相册图片失败, 请重试"
|
|
|
|
|
+ switch (err.errMsg) {
|
|
|
|
|
+ case "chooseImage:fail cancel":
|
|
|
|
|
+ tips = "已取消选择相册图片"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseImage:fail auth deny":
|
|
|
|
|
+ case "chooseImage:fail permission denied":
|
|
|
|
|
+ tips = "未授权相册或摄像头权限,无法访问相册图片"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseImage:fail file not found":
|
|
|
|
|
+ tips = "选择的图片已被删除或移动"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseImage:fail system error":
|
|
|
|
|
+ tips = "微信内部错误,请检查微信版本、重启小程序或设备"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseImage:fail operation too frequent":
|
|
|
|
|
+ tips = "短时间内多次调用,请稍后重试"
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ logManager.error("未处理的选择相册图片失败 errMsg::", JSON.stringify(err.errMsg))
|
|
|
|
|
+ }
|
|
|
|
|
+ toast.warning(tips)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
break;
|
|
break;
|
|
@@ -464,8 +549,9 @@ function selectFile() {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- }).catch(() => {
|
|
|
|
|
|
|
+ }).catch((err) => {
|
|
|
toast.warning("获取发票信息异常")
|
|
toast.warning("获取发票信息异常")
|
|
|
|
|
+ console.log('getInvoiceBatch catch: ', err);
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -473,17 +559,42 @@ function selectFile() {
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
fail (err) {
|
|
fail (err) {
|
|
|
|
|
+ console.log('chooseInvoice err: ', err);
|
|
|
let tips = "选择微信发票失败, 请重试"
|
|
let tips = "选择微信发票失败, 请重试"
|
|
|
switch (err.errMsg) {
|
|
switch (err.errMsg) {
|
|
|
case "chooseInvoice:fail cancel":
|
|
case "chooseInvoice:fail cancel":
|
|
|
- tips = "已取消选择发票"
|
|
|
|
|
|
|
+ tips = "已取消选择微信发票"
|
|
|
break;
|
|
break;
|
|
|
case "chooseInvoice:fail auth deny":
|
|
case "chooseInvoice:fail auth deny":
|
|
|
- tips = "已拒绝授权,无法访问发票信息"
|
|
|
|
|
|
|
+ case "chooseInvoice:fail permission denied":
|
|
|
|
|
+ tips = "未授权发票访问权限,无法访问发票信息"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseInvoice:fail no invoice":
|
|
|
|
|
+ tips = "当前没有可选的发票"
|
|
|
break;
|
|
break;
|
|
|
case "chooseInvoice:fail system error":
|
|
case "chooseInvoice:fail system error":
|
|
|
- tips = "系统错误"
|
|
|
|
|
|
|
+ tips = "微信内部错误,请检查微信版本、重启小程序或设备"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseInvoice:fail invoice expired":
|
|
|
|
|
+ tips = "选择的发票已超过有效期"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseInvoice:fail invoice not supported":
|
|
|
|
|
+ tips = "选择的发票类型不被小程序支持"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseInvoice:fail merchant not match":
|
|
|
|
|
+ tips = "发票所属商户与当前小程序不匹配"
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case "chooseInvoice:fail need verify password":
|
|
|
|
|
+ tips = "需要输入密码才能查看发票"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseInvoice:fail operation too frequent":
|
|
|
|
|
+ tips = "短时间内多次调用,请稍后重试"
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "chooseInvoice:fail 开发者工具暂时不支持此 API 调试,请使用真机进行开发":
|
|
|
|
|
+ tips = "开发者工具暂时不支持此 API 调试,请使用真机进行开发"
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ logManager.error("未处理的选择微信发票失败 errMsg::", JSON.stringify(err.errMsg))
|
|
|
}
|
|
}
|
|
|
toast.warning(tips)
|
|
toast.warning(tips)
|
|
|
}
|
|
}
|
|
@@ -583,7 +694,7 @@ async function handleBatchPrint() {
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
// 上传文件并监听进度
|
|
// 上传文件并监听进度
|
|
|
- const uploadRes = await handlePrint(filePath, (progress) => {
|
|
|
|
|
|
|
+ const uploadRes = await handlePrint(fileName, filePath, (progress) => {
|
|
|
toast.loading({
|
|
toast.loading({
|
|
|
loadingType: 'ring',
|
|
loadingType: 'ring',
|
|
|
msg: `文件 ${i + 1} 上传进度: ${progress}%`
|
|
msg: `文件 ${i + 1} 上传进度: ${progress}%`
|
|
@@ -592,6 +703,8 @@ async function handleBatchPrint() {
|
|
|
toast.success(`文件 ${i + 1} 上传成功`)
|
|
toast.success(`文件 ${i + 1} 上传成功`)
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
toast.error(`文件 ${i + 1} 上传失败`)
|
|
toast.error(`文件 ${i + 1} 上传失败`)
|
|
|
|
|
+ logManager.error(`文件 ${fileName} 上传失败::`, error.errMsg)
|
|
|
|
|
+ console.log('error: ', error);
|
|
|
failedFiles.value.push(fileList.value[i]); // 记录失败的文件
|
|
failedFiles.value.push(fileList.value[i]); // 记录失败的文件
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -605,13 +718,14 @@ async function handleBatchPrint() {
|
|
|
}).then(async () => {
|
|
}).then(async () => {
|
|
|
await retryUploadFiles(failedFiles.value); // 重新上传失败的文件
|
|
await retryUploadFiles(failedFiles.value); // 重新上传失败的文件
|
|
|
}).catch((error) => {
|
|
}).catch((error) => {
|
|
|
- msgConfirm("上传完成", "取消重新上传, 其余文件已上传成功!")
|
|
|
|
|
|
|
+ msgConfirm("提示", `已取消重新上传${failedFiles.value.length < fileList.value.length ? ', 其余文件已上传成功!' : ""}`)
|
|
|
})
|
|
})
|
|
|
} else {
|
|
} else {
|
|
|
toast.success("所有文件上传成功")
|
|
toast.success("所有文件上传成功")
|
|
|
msgConfirm("上传完成", "所有文件上传成功")
|
|
msgConfirm("上传完成", "所有文件上传成功")
|
|
|
}
|
|
}
|
|
|
} catch(error) {
|
|
} catch(error) {
|
|
|
|
|
+ logManager.error(`上传过程中发生错误::`, JSON.stringify(error))
|
|
|
console.log("上传过程中发生错误", error);
|
|
console.log("上传过程中发生错误", error);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -629,7 +743,7 @@ async function retryUploadFiles(failedFiles) {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- const uploadRes = await handlePrint(filePath, (progress) => {
|
|
|
|
|
|
|
+ const uploadRes = await handlePrint(fileName, filePath, (progress) => {
|
|
|
toast.loading({
|
|
toast.loading({
|
|
|
loadingType: 'ring',
|
|
loadingType: 'ring',
|
|
|
msg: `文件 ${i + 1} 上传进度: ${progress}%`
|
|
msg: `文件 ${i + 1} 上传进度: ${progress}%`
|
|
@@ -637,7 +751,8 @@ async function retryUploadFiles(failedFiles) {
|
|
|
});
|
|
});
|
|
|
toast.success(`文件 ${i + 1} 重新上传成功`)
|
|
toast.success(`文件 ${i + 1} 重新上传成功`)
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- toast.error(`文件 ${i + 1} 重新上传成功`)
|
|
|
|
|
|
|
+ toast.error(`文件 ${i + 1} 重新上传失败`)
|
|
|
|
|
+ logManager.error(`文件重新上传失败 :: 文件名 ${fileName} :: 文件路径 ${filePath} :: `, JSON.stringify(error))
|
|
|
newFailedFiles.push(failedFiles[i]); // 记录重新上传失败的文件
|
|
newFailedFiles.push(failedFiles[i]); // 记录重新上传失败的文件
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -657,12 +772,13 @@ async function retryUploadFiles(failedFiles) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 打印文件 (单个打印任务)
|
|
// 打印文件 (单个打印任务)
|
|
|
-function handlePrint(filePath, onProgress) {
|
|
|
|
|
|
|
+function handlePrint(fileName, filePath, onProgress) {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
// 构造提交数据
|
|
// 构造提交数据
|
|
|
let params = {
|
|
let params = {
|
|
|
id: formData.value.userHubId,
|
|
id: formData.value.userHubId,
|
|
|
printer: formData.value.printerName,
|
|
printer: formData.value.printerName,
|
|
|
|
|
+ originalName: fileName,
|
|
|
}
|
|
}
|
|
|
printerOptions.value.forEach(option => {
|
|
printerOptions.value.forEach(option => {
|
|
|
switch(option.type) {
|
|
switch(option.type) {
|
|
@@ -687,18 +803,20 @@ function handlePrint(filePath, onProgress) {
|
|
|
url: getURL(),
|
|
url: getURL(),
|
|
|
filePath: filePath,
|
|
filePath: filePath,
|
|
|
name: 'file', // 文件对应的 key
|
|
name: 'file', // 文件对应的 key
|
|
|
- formData: {
|
|
|
|
|
- // 其他表单数据
|
|
|
|
|
|
|
+ formData: { // 其他表单数据
|
|
|
|
|
+ originalName: fileName // 文件名称
|
|
|
},
|
|
},
|
|
|
success: (res) => {
|
|
success: (res) => {
|
|
|
if (res.statusCode === 200 && ((isLocal.value && JSON.parse(res.data).code === 200) || (!isLocal.value && JSON.parse(res.data).code === 0))) {
|
|
if (res.statusCode === 200 && ((isLocal.value && JSON.parse(res.data).code === 200) || (!isLocal.value && JSON.parse(res.data).code === 0))) {
|
|
|
resolve(res.data);
|
|
resolve(res.data);
|
|
|
} else {
|
|
} else {
|
|
|
reject(new Error(`上传失败,状态码: ${res.statusCode}`));
|
|
reject(new Error(`上传失败,状态码: ${res.statusCode}`));
|
|
|
|
|
+ logManager.error(`上传失败,状态码: ${res.statusCode}`)
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
fail: (err) => {
|
|
fail: (err) => {
|
|
|
reject(err);
|
|
reject(err);
|
|
|
|
|
+ logManager.error(`上传失败,fail err:: ${JSON.stringify(err)}`)
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -787,15 +905,6 @@ function msgConfirm(title="提示", msg="文件已上传成功!") {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 打开SSE webview页面
|
|
|
|
|
-// function openWebViewSSE() {
|
|
|
|
|
-// let list = JSON.stringify(fileList.value.map(item => item.name).join(",") || "")
|
|
|
|
|
-// const url = `https://service.1ai.ltd/webview-sse/index.html?token=${token}&list=${list}&t=${new Date().getTime()}`
|
|
|
|
|
-// uni.navigateTo({
|
|
|
|
|
-// url: `/pages/webview/sse?url=${encodeURIComponent(url)}`,
|
|
|
|
|
-// })
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
onLoad((option) => {
|
|
onLoad((option) => {
|
|
|
if (option && option.accept) {
|
|
if (option && option.accept) {
|
|
|
accept.value = option.accept
|
|
accept.value = option.accept
|