@uxda/appkit 4.3.5 → 4.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +130 -23
- package/package.json +1 -1
- package/src/balance/components/PromoterCard.vue +1 -0
- package/src/payment/components/TradeView.vue +51 -3
- package/src/shared/components/OcrInvoice.vue +124 -20
- package/src/shared/weixin/jssdk.ts +1 -0
- package/src/user/components/UserInfo.vue +1 -0
package/dist/index.js
CHANGED
|
@@ -128,6 +128,7 @@ function requestWxH5Pay(options) {
|
|
|
128
128
|
title: "\u63D0\u793A",
|
|
129
129
|
content: "\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u5FAE\u4FE1\u652F\u4ED8\uFF0C\u8BF7\u5728\u5FAE\u4FE1\u5185\u7F6E\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00",
|
|
130
130
|
confirmText: "\u786E\u5B9A",
|
|
131
|
+
confirmColor: "#017fff",
|
|
131
132
|
success: () => {
|
|
132
133
|
}
|
|
133
134
|
});
|
|
@@ -1718,13 +1719,30 @@ var script$F = /* @__PURE__ */ defineComponent({
|
|
|
1718
1719
|
const $http = useHttp$3(), $n = useNutshell();
|
|
1719
1720
|
const emits = __emit;
|
|
1720
1721
|
const props = __props;
|
|
1721
|
-
|
|
1722
|
+
function getFileType(filePath, fileName) {
|
|
1723
|
+
const lowerPath = filePath.toLowerCase();
|
|
1724
|
+
const lowerName = (fileName || "").toLowerCase();
|
|
1725
|
+
if (lowerPath.endsWith(".pdf") || lowerName.endsWith(".pdf")) {
|
|
1726
|
+
return "pdf";
|
|
1727
|
+
}
|
|
1728
|
+
const imageExtensions = [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp"];
|
|
1729
|
+
if (imageExtensions.some((ext) => lowerPath.endsWith(ext) || lowerName.endsWith(ext))) {
|
|
1730
|
+
return "img";
|
|
1731
|
+
}
|
|
1732
|
+
return "img";
|
|
1733
|
+
}
|
|
1734
|
+
async function onUploadFile(csRes, fileType) {
|
|
1722
1735
|
try {
|
|
1723
|
-
let { path, size, tempFilePath } = csRes.tempFiles[0];
|
|
1724
|
-
const
|
|
1725
|
-
const
|
|
1736
|
+
let { path, size, tempFilePath, name } = csRes.tempFiles[0];
|
|
1737
|
+
const originalPath = path || tempFilePath;
|
|
1738
|
+
const detectedFileType = fileType || getFileType(originalPath, name);
|
|
1739
|
+
let filePath = originalPath;
|
|
1740
|
+
if (detectedFileType === "img") {
|
|
1741
|
+
const compressImg = await compressImage(originalPath, getCompressQuality(size)) || {};
|
|
1742
|
+
filePath = compressImg.tempFilePath || originalPath;
|
|
1743
|
+
}
|
|
1726
1744
|
if (props.customUpload) {
|
|
1727
|
-
props.customUpload(filePath);
|
|
1745
|
+
props.customUpload(filePath, detectedFileType);
|
|
1728
1746
|
return;
|
|
1729
1747
|
}
|
|
1730
1748
|
showLoading({ title: "\u53D1\u7968\u8BC6\u522B\u4E2D..", mask: true });
|
|
@@ -1744,7 +1762,7 @@ var script$F = /* @__PURE__ */ defineComponent({
|
|
|
1744
1762
|
});
|
|
1745
1763
|
const res = JSON.parse(upRes.data);
|
|
1746
1764
|
if (res.code === "200") {
|
|
1747
|
-
await getOcrInfo(res.result);
|
|
1765
|
+
await getOcrInfo(res.result, detectedFileType);
|
|
1748
1766
|
} else {
|
|
1749
1767
|
hideLoading();
|
|
1750
1768
|
showToast({
|
|
@@ -1757,17 +1775,18 @@ var script$F = /* @__PURE__ */ defineComponent({
|
|
|
1757
1775
|
console.log(err);
|
|
1758
1776
|
}
|
|
1759
1777
|
}
|
|
1760
|
-
async function getOcrInfo(file) {
|
|
1778
|
+
async function getOcrInfo(file, fileType = "img") {
|
|
1761
1779
|
try {
|
|
1780
|
+
const fileUrl = typeof file === "string" ? file : file.originalUrl;
|
|
1762
1781
|
const res = await $http.get("/hkbase/common/vatInvoice", {
|
|
1763
|
-
fileUrl
|
|
1764
|
-
fileType
|
|
1782
|
+
fileUrl,
|
|
1783
|
+
fileType
|
|
1765
1784
|
});
|
|
1766
1785
|
hideLoading();
|
|
1767
1786
|
if (!res?.purchaserRegisterNum) {
|
|
1768
1787
|
$n.dialog({
|
|
1769
1788
|
title: "\u8BC6\u522B\u5931\u8D25",
|
|
1770
|
-
message: `\u60A8\u4E0A\u4F20\u7684\u56FE\u7247\u53EF\u80FD\u4E0D\u591F\u6E05\u6670\u6216\u4E0E\u5F53\u524D\u529F\u80FD\u4E0D\u7B26\uFF0C\u8BF7\u91CD\u65B0\u4E0A\u4F20\u4E00\u5F20\u6E05\u6670\u3001\u5B8C\u6574\u7684\u56FE\u7247\u3002\u8C22\u8C22\uFF01`,
|
|
1789
|
+
message: `\u60A8\u4E0A\u4F20\u7684${fileType === "pdf" ? "\u6587\u4EF6" : "\u56FE\u7247"}\u53EF\u80FD\u4E0D\u591F\u6E05\u6670\u6216\u4E0E\u5F53\u524D\u529F\u80FD\u4E0D\u7B26\uFF0C\u8BF7\u91CD\u65B0\u4E0A\u4F20\u4E00\u5F20\u6E05\u6670\u3001\u5B8C\u6574\u7684${fileType === "pdf" ? "PDF\u6587\u4EF6" : "\u56FE\u7247"}\u3002\u8C22\u8C22\uFF01`,
|
|
1771
1790
|
okText: "\u6211\u77E5\u9053\u4E86",
|
|
1772
1791
|
cancelText: ""
|
|
1773
1792
|
});
|
|
@@ -1788,7 +1807,8 @@ var script$F = /* @__PURE__ */ defineComponent({
|
|
|
1788
1807
|
serviceType: res?.serviceType,
|
|
1789
1808
|
totalAmount: res?.totalAmount,
|
|
1790
1809
|
totalTax: res?.totalTax,
|
|
1791
|
-
fileUrl
|
|
1810
|
+
fileUrl,
|
|
1811
|
+
fileType,
|
|
1792
1812
|
fileKey: typeof file === "string" ? file : file.fileId
|
|
1793
1813
|
});
|
|
1794
1814
|
} catch (err) {
|
|
@@ -1808,10 +1828,14 @@ var script$F = /* @__PURE__ */ defineComponent({
|
|
|
1808
1828
|
{
|
|
1809
1829
|
name: "\u4ECE\u804A\u5929\u4F1A\u8BDD\u9009\u62E9",
|
|
1810
1830
|
type: "message"
|
|
1831
|
+
},
|
|
1832
|
+
{
|
|
1833
|
+
name: "\u9009\u62E9\u6587\u4EF6",
|
|
1834
|
+
type: "file"
|
|
1811
1835
|
}
|
|
1812
1836
|
];
|
|
1813
1837
|
if (Taro.getEnv() === "WEB") {
|
|
1814
|
-
actionSheetMenus.
|
|
1838
|
+
actionSheetMenus.splice(2, 1);
|
|
1815
1839
|
}
|
|
1816
1840
|
async function chooseImages(item) {
|
|
1817
1841
|
if (["camera", "album"].includes(item.type)) {
|
|
@@ -1823,25 +1847,72 @@ var script$F = /* @__PURE__ */ defineComponent({
|
|
|
1823
1847
|
// 使用duration属性判断是图片还是视频,图片没有该属性
|
|
1824
1848
|
});
|
|
1825
1849
|
onUploadFile(csRes);
|
|
1826
|
-
} else {
|
|
1850
|
+
} else if (item.type === "message") {
|
|
1827
1851
|
const csRes = await chooseMessageFile({
|
|
1828
1852
|
count: 1,
|
|
1829
1853
|
type: "image"
|
|
1830
1854
|
});
|
|
1831
1855
|
onUploadFile(csRes);
|
|
1856
|
+
} else if (item.type === "file") {
|
|
1857
|
+
const csRes = await chooseMessageFile({
|
|
1858
|
+
count: 1,
|
|
1859
|
+
type: "file"
|
|
1860
|
+
});
|
|
1861
|
+
onUploadFile(csRes);
|
|
1832
1862
|
}
|
|
1833
1863
|
}
|
|
1864
|
+
function chooseFileInWeb() {
|
|
1865
|
+
return new Promise((resolve, reject) => {
|
|
1866
|
+
const input = document.createElement("input");
|
|
1867
|
+
input.type = "file";
|
|
1868
|
+
input.accept = "image/*,.pdf";
|
|
1869
|
+
input.style.display = "none";
|
|
1870
|
+
input.onchange = async (e) => {
|
|
1871
|
+
const file = e.target?.files?.[0];
|
|
1872
|
+
if (!file) {
|
|
1873
|
+
document.body.removeChild(input);
|
|
1874
|
+
resolve();
|
|
1875
|
+
return;
|
|
1876
|
+
}
|
|
1877
|
+
let fileType = "img";
|
|
1878
|
+
if (file.type === "application/pdf" || file.name.toLowerCase().endsWith(".pdf")) {
|
|
1879
|
+
fileType = "pdf";
|
|
1880
|
+
}
|
|
1881
|
+
const filePath = URL.createObjectURL(file);
|
|
1882
|
+
try {
|
|
1883
|
+
const csRes = {
|
|
1884
|
+
tempFiles: [{
|
|
1885
|
+
path: filePath,
|
|
1886
|
+
tempFilePath: filePath,
|
|
1887
|
+
size: file.size,
|
|
1888
|
+
name: file.name
|
|
1889
|
+
}]
|
|
1890
|
+
};
|
|
1891
|
+
await onUploadFile(csRes, fileType);
|
|
1892
|
+
resolve();
|
|
1893
|
+
} catch (error) {
|
|
1894
|
+
reject(error);
|
|
1895
|
+
} finally {
|
|
1896
|
+
document.body.removeChild(input);
|
|
1897
|
+
URL.revokeObjectURL(filePath);
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
input.oncancel = () => {
|
|
1901
|
+
document.body.removeChild(input);
|
|
1902
|
+
resolve();
|
|
1903
|
+
};
|
|
1904
|
+
document.body.appendChild(input);
|
|
1905
|
+
input.click();
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1834
1908
|
async function onUpload() {
|
|
1835
1909
|
if (props.disabled) return;
|
|
1836
1910
|
if (Taro.getEnv() === "WEB") {
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
// 使用duration属性判断是图片还是视频,图片没有该属性
|
|
1843
|
-
});
|
|
1844
|
-
onUploadFile(csRes);
|
|
1911
|
+
try {
|
|
1912
|
+
await chooseFileInWeb();
|
|
1913
|
+
} catch (err) {
|
|
1914
|
+
console.error("\u6587\u4EF6\u9009\u62E9\u5931\u8D25:", err);
|
|
1915
|
+
}
|
|
1845
1916
|
return;
|
|
1846
1917
|
}
|
|
1847
1918
|
activeSheetVisible.value = true;
|
|
@@ -3795,7 +3866,8 @@ var script$A = /* @__PURE__ */ defineComponent({
|
|
|
3795
3866
|
headerApp: { type: String, required: true },
|
|
3796
3867
|
app: { type: String, required: true },
|
|
3797
3868
|
tenant: { type: String, required: true },
|
|
3798
|
-
payFinishJumpUrl: { type: String, required: false }
|
|
3869
|
+
payFinishJumpUrl: { type: String, required: false },
|
|
3870
|
+
apps: { type: String, required: false }
|
|
3799
3871
|
},
|
|
3800
3872
|
emits: ["complete", "agree"],
|
|
3801
3873
|
setup(__props, { emit: __emit }) {
|
|
@@ -3959,13 +4031,46 @@ var script$A = /* @__PURE__ */ defineComponent({
|
|
|
3959
4031
|
});
|
|
3960
4032
|
}
|
|
3961
4033
|
}
|
|
3962
|
-
const onPayClick = () => {
|
|
4034
|
+
const onPayClick = async () => {
|
|
3963
4035
|
if (selectBean.value && !isCombinedPayment.value) {
|
|
3964
4036
|
showDialog.value = true;
|
|
3965
4037
|
return;
|
|
3966
4038
|
}
|
|
4039
|
+
if (isCombinedPayment.value) {
|
|
4040
|
+
const res = await checkBalance();
|
|
4041
|
+
if (!res) return;
|
|
4042
|
+
}
|
|
3967
4043
|
proceedWechatPayment();
|
|
3968
4044
|
};
|
|
4045
|
+
async function checkBalance() {
|
|
4046
|
+
const $http = useHttp$2();
|
|
4047
|
+
return new Promise((resolve, reject) => {
|
|
4048
|
+
state.buttonLoading = true;
|
|
4049
|
+
$http.get(endpoints$2.\u83B7\u53D6\u4F59\u989D\u660E\u7EC6, {
|
|
4050
|
+
app: props.apps
|
|
4051
|
+
}).then((data) => {
|
|
4052
|
+
state.buttonLoading = false;
|
|
4053
|
+
if (data.commonAccount < balance.value) {
|
|
4054
|
+
showModal({
|
|
4055
|
+
title: "\u6E29\u99A8\u63D0\u793A",
|
|
4056
|
+
content: "\u4E91\u8C46\u4E0D\u8DB3\uFF0C\u8BF7\u5237\u65B0\u540E\u518D\u6B21\u786E\u8BA4",
|
|
4057
|
+
showCancel: false,
|
|
4058
|
+
confirmText: "\u5237\u65B0",
|
|
4059
|
+
confirmColor: "#017fff",
|
|
4060
|
+
success: () => {
|
|
4061
|
+
balance.value = data.commonAccount;
|
|
4062
|
+
}
|
|
4063
|
+
});
|
|
4064
|
+
resolve(false);
|
|
4065
|
+
} else {
|
|
4066
|
+
resolve(true);
|
|
4067
|
+
}
|
|
4068
|
+
}).catch((error) => {
|
|
4069
|
+
state.buttonLoading = false;
|
|
4070
|
+
resolve(false);
|
|
4071
|
+
});
|
|
4072
|
+
});
|
|
4073
|
+
}
|
|
3969
4074
|
return (_ctx, _cache) => {
|
|
3970
4075
|
const _component_nut_checkbox = Checkbox;
|
|
3971
4076
|
const _component_nut_button = Button;
|
|
@@ -5960,6 +6065,7 @@ var script$o = /* @__PURE__ */ defineComponent({
|
|
|
5960
6065
|
showModal({
|
|
5961
6066
|
content: toastMap[type],
|
|
5962
6067
|
showCancel: false,
|
|
6068
|
+
confirmColor: "#017fff",
|
|
5963
6069
|
confirmText: "\u77E5\u9053\u4E86"
|
|
5964
6070
|
});
|
|
5965
6071
|
}
|
|
@@ -8639,6 +8745,7 @@ var script$b = /* @__PURE__ */ defineComponent({
|
|
|
8639
8745
|
title: "\u63D0\u793A",
|
|
8640
8746
|
content: "\u786E\u5B9A\u8981\u9000\u51FA\u767B\u5F55\u5417\uFF1F",
|
|
8641
8747
|
confirmText: "\u786E\u5B9A",
|
|
8748
|
+
confirmColor: "#017fff",
|
|
8642
8749
|
success: async (e) => {
|
|
8643
8750
|
if (e.confirm) {
|
|
8644
8751
|
emits("logout");
|
package/package.json
CHANGED
|
@@ -104,8 +104,9 @@
|
|
|
104
104
|
import { computed, onMounted, reactive, ref } from "vue";
|
|
105
105
|
import RightsPicker, { Amount } from "./RightsPicker.vue";
|
|
106
106
|
import { endpoints, useHttp } from "../api";
|
|
107
|
+
import { endpoints as balanceEndpoints } from "../../balance/api";
|
|
107
108
|
import { requestBrandWCPayByBean, requestPaymentByBean } from "../services";
|
|
108
|
-
import Taro, { showToast, useRouter } from "@tarojs/taro";
|
|
109
|
+
import Taro, { showToast, useRouter, showModal } from "@tarojs/taro";
|
|
109
110
|
import { useAmount } from "../../shared/composables/useAmount";
|
|
110
111
|
import { isWechat } from "../../shared/composables/useDeviceEnv";
|
|
111
112
|
|
|
@@ -134,6 +135,10 @@ export interface RechargeViewProps {
|
|
|
134
135
|
* h5支付完成后跳转地址
|
|
135
136
|
*/
|
|
136
137
|
payFinishJumpUrl?: "";
|
|
138
|
+
/**
|
|
139
|
+
* 所有应用
|
|
140
|
+
**/
|
|
141
|
+
apps?: string;
|
|
137
142
|
}
|
|
138
143
|
|
|
139
144
|
const props = defineProps<RechargeViewProps>();
|
|
@@ -339,16 +344,59 @@ function proceedWechatPayment() {
|
|
|
339
344
|
}
|
|
340
345
|
}
|
|
341
346
|
|
|
342
|
-
const onPayClick = () => {
|
|
347
|
+
const onPayClick = async () => {
|
|
343
348
|
// 用云豆支付(纯云豆支付)
|
|
344
349
|
if (selectBean.value && !isCombinedPayment.value) {
|
|
345
350
|
showDialog.value = true;
|
|
346
351
|
return;
|
|
347
352
|
}
|
|
348
353
|
|
|
354
|
+
if (isCombinedPayment.value) {
|
|
355
|
+
// 检验云豆是否已经改变,改变则刷新选择
|
|
356
|
+
const res = await checkBalance()
|
|
357
|
+
if (!res) return
|
|
358
|
+
}
|
|
359
|
+
|
|
349
360
|
// 纯微信支付
|
|
350
361
|
proceedWechatPayment();
|
|
351
|
-
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* 校验余额是否充足
|
|
366
|
+
*/
|
|
367
|
+
async function checkBalance() {
|
|
368
|
+
const $http = useHttp()
|
|
369
|
+
return new Promise((resolve, reject) => {
|
|
370
|
+
state.buttonLoading = true;
|
|
371
|
+
$http
|
|
372
|
+
.get<any>(balanceEndpoints.获取余额明细, {
|
|
373
|
+
app: props.apps,
|
|
374
|
+
})
|
|
375
|
+
.then((data) => {
|
|
376
|
+
state.buttonLoading = false;
|
|
377
|
+
if (data.commonAccount < balance.value) {
|
|
378
|
+
showModal({
|
|
379
|
+
title: '温馨提示',
|
|
380
|
+
content: '云豆不足,请刷新后再次确认',
|
|
381
|
+
showCancel: false,
|
|
382
|
+
confirmText: '刷新',
|
|
383
|
+
confirmColor: '#017fff',
|
|
384
|
+
success: () => {
|
|
385
|
+
balance.value = data.commonAccount;
|
|
386
|
+
}
|
|
387
|
+
})
|
|
388
|
+
resolve(false)
|
|
389
|
+
|
|
390
|
+
} else {
|
|
391
|
+
resolve(true)
|
|
392
|
+
}
|
|
393
|
+
}).catch((error) => {
|
|
394
|
+
state.buttonLoading = false;
|
|
395
|
+
resolve(false)
|
|
396
|
+
})
|
|
397
|
+
})
|
|
398
|
+
}
|
|
399
|
+
|
|
352
400
|
</script>
|
|
353
401
|
|
|
354
402
|
<style lang="scss">
|
|
@@ -49,14 +49,45 @@ const props = withDefaults(defineProps<OcrProps>(), {
|
|
|
49
49
|
customClick: false
|
|
50
50
|
})
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* 判断文件类型
|
|
54
|
+
*/
|
|
55
|
+
function getFileType(filePath: string, fileName?: string): 'img' | 'pdf' {
|
|
56
|
+
const lowerPath = filePath.toLowerCase()
|
|
57
|
+
const lowerName = (fileName || '').toLowerCase()
|
|
58
|
+
|
|
59
|
+
// 检查文件扩展名
|
|
60
|
+
if (lowerPath.endsWith('.pdf') || lowerName.endsWith('.pdf')) {
|
|
61
|
+
return 'pdf'
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 检查是否为图片格式
|
|
65
|
+
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp']
|
|
66
|
+
if (imageExtensions.some(ext => lowerPath.endsWith(ext) || lowerName.endsWith(ext))) {
|
|
67
|
+
return 'img'
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 默认为图片
|
|
71
|
+
return 'img'
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function onUploadFile(csRes: any, fileType?: 'img' | 'pdf') {
|
|
53
75
|
try {
|
|
54
|
-
let { path, size, tempFilePath } = csRes.tempFiles[0]
|
|
55
|
-
const
|
|
56
|
-
|
|
76
|
+
let { path, size, tempFilePath, name } = csRes.tempFiles[0]
|
|
77
|
+
const originalPath = path || tempFilePath
|
|
78
|
+
|
|
79
|
+
// 判断文件类型
|
|
80
|
+
const detectedFileType = fileType || getFileType(originalPath, name)
|
|
81
|
+
|
|
82
|
+
// 只有图片才进行压缩
|
|
83
|
+
let filePath = originalPath
|
|
84
|
+
if (detectedFileType === 'img') {
|
|
85
|
+
const compressImg: any = (await compressImage(originalPath, getCompressQuality(size))) || {}
|
|
86
|
+
filePath = compressImg.tempFilePath || originalPath
|
|
87
|
+
}
|
|
57
88
|
|
|
58
89
|
if (props.customUpload) {
|
|
59
|
-
props.customUpload(filePath)
|
|
90
|
+
props.customUpload(filePath, detectedFileType)
|
|
60
91
|
return
|
|
61
92
|
}
|
|
62
93
|
|
|
@@ -79,7 +110,7 @@ async function onUploadFile(csRes: any) {
|
|
|
79
110
|
|
|
80
111
|
const res = JSON.parse(upRes.data)
|
|
81
112
|
if (res.code === '200') {
|
|
82
|
-
await getOcrInfo(res.result)
|
|
113
|
+
await getOcrInfo(res.result, detectedFileType)
|
|
83
114
|
} else {
|
|
84
115
|
hideLoading()
|
|
85
116
|
showToast({
|
|
@@ -94,18 +125,19 @@ async function onUploadFile(csRes: any) {
|
|
|
94
125
|
}
|
|
95
126
|
|
|
96
127
|
// 根据证件路径获取证件信息
|
|
97
|
-
async function getOcrInfo(file: string | FileType) {
|
|
128
|
+
async function getOcrInfo(file: string | FileType, fileType: 'img' | 'pdf' = 'img') {
|
|
98
129
|
try {
|
|
130
|
+
const fileUrl = typeof file === 'string' ? file : file.originalUrl
|
|
99
131
|
const res: any = await $http.get('/hkbase/common/vatInvoice', {
|
|
100
|
-
fileUrl
|
|
101
|
-
fileType:
|
|
132
|
+
fileUrl,
|
|
133
|
+
fileType: fileType
|
|
102
134
|
})
|
|
103
135
|
hideLoading()
|
|
104
136
|
|
|
105
137
|
if (!res?.purchaserRegisterNum) {
|
|
106
138
|
$n.dialog({
|
|
107
139
|
title: '识别失败',
|
|
108
|
-
message:
|
|
140
|
+
message: `您上传的${fileType === 'pdf' ? '文件' : '图片'}可能不够清晰或与当前功能不符,请重新上传一张清晰、完整的${fileType === 'pdf' ? 'PDF文件' : '图片'}。谢谢!`,
|
|
109
141
|
okText: '我知道了',
|
|
110
142
|
cancelText: '',
|
|
111
143
|
})
|
|
@@ -127,7 +159,8 @@ async function getOcrInfo(file: string | FileType) {
|
|
|
127
159
|
serviceType: res?.serviceType,
|
|
128
160
|
totalAmount: res?.totalAmount,
|
|
129
161
|
totalTax: res?.totalTax,
|
|
130
|
-
fileUrl:
|
|
162
|
+
fileUrl: fileUrl,
|
|
163
|
+
fileType: fileType,
|
|
131
164
|
fileKey: typeof file === 'string' ? file : file.fileId,
|
|
132
165
|
})
|
|
133
166
|
} catch (err) {
|
|
@@ -150,9 +183,14 @@ const actionSheetMenus = [
|
|
|
150
183
|
name: '从聊天会话选择',
|
|
151
184
|
type: 'message',
|
|
152
185
|
},
|
|
186
|
+
{
|
|
187
|
+
name: '选择文件',
|
|
188
|
+
type: 'file',
|
|
189
|
+
},
|
|
153
190
|
]
|
|
154
191
|
if (Taro.getEnv() === 'WEB') {
|
|
155
|
-
|
|
192
|
+
// Web 端移除"从聊天会话选择",保留"选择文件"
|
|
193
|
+
actionSheetMenus.splice(2, 1)
|
|
156
194
|
}
|
|
157
195
|
|
|
158
196
|
// 选择图像上传
|
|
@@ -165,27 +203,93 @@ async function chooseImages(item: any) {
|
|
|
165
203
|
})
|
|
166
204
|
|
|
167
205
|
onUploadFile(csRes)
|
|
168
|
-
} else {
|
|
206
|
+
} else if (item.type === 'message') {
|
|
169
207
|
const csRes = await chooseMessageFile({
|
|
170
208
|
count: 1,
|
|
171
209
|
type: 'image',
|
|
172
210
|
})
|
|
173
211
|
|
|
212
|
+
onUploadFile(csRes)
|
|
213
|
+
} else if (item.type === 'file') {
|
|
214
|
+
// 选择文件(包括PDF)
|
|
215
|
+
const csRes = await chooseMessageFile({
|
|
216
|
+
count: 1,
|
|
217
|
+
type: 'file',
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
// 不预先指定类型,让 onUploadFile 根据文件名自动判断
|
|
174
221
|
onUploadFile(csRes)
|
|
175
222
|
}
|
|
176
223
|
}
|
|
177
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Web 端选择文件(支持图片和PDF)
|
|
227
|
+
*/
|
|
228
|
+
function chooseFileInWeb() {
|
|
229
|
+
return new Promise<void>((resolve, reject) => {
|
|
230
|
+
const input = document.createElement('input')
|
|
231
|
+
input.type = 'file'
|
|
232
|
+
input.accept = 'image/*,.pdf'
|
|
233
|
+
input.style.display = 'none'
|
|
234
|
+
|
|
235
|
+
input.onchange = async (e: any) => {
|
|
236
|
+
const file = e.target?.files?.[0]
|
|
237
|
+
if (!file) {
|
|
238
|
+
document.body.removeChild(input)
|
|
239
|
+
resolve()
|
|
240
|
+
return
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// 根据文件 MIME 类型和扩展名判断文件类型
|
|
244
|
+
let fileType: 'img' | 'pdf' = 'img'
|
|
245
|
+
if (file.type === 'application/pdf' || file.name.toLowerCase().endsWith('.pdf')) {
|
|
246
|
+
fileType = 'pdf'
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const filePath = URL.createObjectURL(file)
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
// 构造类似 chooseMedia 返回的数据结构
|
|
253
|
+
const csRes = {
|
|
254
|
+
tempFiles: [{
|
|
255
|
+
path: filePath,
|
|
256
|
+
tempFilePath: filePath,
|
|
257
|
+
size: file.size,
|
|
258
|
+
name: file.name,
|
|
259
|
+
}]
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
await onUploadFile(csRes, fileType)
|
|
263
|
+
resolve()
|
|
264
|
+
} catch (error) {
|
|
265
|
+
reject(error)
|
|
266
|
+
} finally {
|
|
267
|
+
document.body.removeChild(input)
|
|
268
|
+
// 清理 blob URL
|
|
269
|
+
URL.revokeObjectURL(filePath)
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
input.oncancel = () => {
|
|
274
|
+
document.body.removeChild(input)
|
|
275
|
+
resolve()
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
document.body.appendChild(input)
|
|
279
|
+
input.click()
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
|
|
178
283
|
async function onUpload() {
|
|
179
284
|
if (props.disabled) return
|
|
180
285
|
|
|
181
286
|
if (Taro.getEnv() === 'WEB') {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
onUploadFile(csRes)
|
|
287
|
+
// Web 端弹出选择:图片或PDF
|
|
288
|
+
try {
|
|
289
|
+
await chooseFileInWeb()
|
|
290
|
+
} catch (err) {
|
|
291
|
+
console.error('文件选择失败:', err)
|
|
292
|
+
}
|
|
189
293
|
return
|
|
190
294
|
}
|
|
191
295
|
|