xyvcard-wechat-auth 0.0.30 → 0.0.31
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/components/common/auth-form/form-upload-file/index.d.ts +1 -0
- package/dist/components/common/auth-form/form-upload-file/index.js +127 -0
- package/dist/components/common/auth-form/form-upload-file/index.json +7 -0
- package/dist/components/common/auth-form/form-upload-file/index.wxml +8 -0
- package/dist/components/common/auth-form/form-upload-file/index.wxss +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { config } from "../../../../utils/config.js";
|
|
2
|
+
import { fileApi } from "../../../../api/files/index.js";
|
|
3
|
+
Component({
|
|
4
|
+
/**
|
|
5
|
+
* 组件的属性列表
|
|
6
|
+
*/
|
|
7
|
+
properties: {
|
|
8
|
+
// 按钮样式
|
|
9
|
+
fileStyle: {
|
|
10
|
+
type: String,
|
|
11
|
+
value: "background-color: #2563EB"
|
|
12
|
+
},
|
|
13
|
+
// 租户
|
|
14
|
+
tenant: {
|
|
15
|
+
type: String,
|
|
16
|
+
value: config.tenant
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
/**
|
|
20
|
+
* 组件的初始数据
|
|
21
|
+
*/
|
|
22
|
+
data: {
|
|
23
|
+
closeModel: false,
|
|
24
|
+
percentage: 100
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* 组件的方法列表
|
|
28
|
+
*/
|
|
29
|
+
methods: {
|
|
30
|
+
// 文件选择
|
|
31
|
+
chooseFileModel() {
|
|
32
|
+
this.setData({
|
|
33
|
+
closeModel: true
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
// 从相册中选择
|
|
37
|
+
handleAlbumImg() {
|
|
38
|
+
const that = this;
|
|
39
|
+
that.setData({
|
|
40
|
+
closeModel: !that.data.closeModel
|
|
41
|
+
});
|
|
42
|
+
wx.chooseMedia({
|
|
43
|
+
count: 20,
|
|
44
|
+
mediaType: ["image"],
|
|
45
|
+
sourceType: ["album"],
|
|
46
|
+
success(response) {
|
|
47
|
+
console.log(response);
|
|
48
|
+
if (response.errMsg === "chooseMedia:ok") {
|
|
49
|
+
console.log(response);
|
|
50
|
+
const tempFilePaths = response.tempFiles;
|
|
51
|
+
console.log(tempFilePaths);
|
|
52
|
+
tempFilePaths.forEach((item) => {
|
|
53
|
+
console.log(item);
|
|
54
|
+
item.name = Math.random() + ".jpg";
|
|
55
|
+
const fs = wx.getFileSystemManager();
|
|
56
|
+
const bodySize = 3670016;
|
|
57
|
+
let part = 1;
|
|
58
|
+
const total = Math.ceil(item.size / bodySize);
|
|
59
|
+
that.updateWebFilePart(fs, item, Math.random() + "123", bodySize, part, total);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
// 上传附件
|
|
66
|
+
handleUploadFile() {
|
|
67
|
+
const that = this;
|
|
68
|
+
that.setData({
|
|
69
|
+
closeModel: !that.data.closeModel
|
|
70
|
+
});
|
|
71
|
+
wx.chooseMessageFile({
|
|
72
|
+
count: 100,
|
|
73
|
+
type: "all",
|
|
74
|
+
// extension: extension,
|
|
75
|
+
success(response) {
|
|
76
|
+
if (response.errMsg === "chooseMessageFile:ok") {
|
|
77
|
+
console.log(response);
|
|
78
|
+
const tempFilePaths = response.tempFiles;
|
|
79
|
+
console.log(tempFilePaths);
|
|
80
|
+
tempFilePaths.forEach((item) => {
|
|
81
|
+
console.log(item);
|
|
82
|
+
const fs = wx.getFileSystemManager();
|
|
83
|
+
const bodySize = 3670016;
|
|
84
|
+
let part = 1;
|
|
85
|
+
const total = Math.ceil(item.size / bodySize);
|
|
86
|
+
that.updateWebFilePart(fs, item, Math.random() + "123", bodySize, part, total);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
updateWebFilePart(fs, item, requestId, bodySize, part, total) {
|
|
93
|
+
console.log(bodySize, part, total);
|
|
94
|
+
let that = this;
|
|
95
|
+
const position = (part - 1) * bodySize;
|
|
96
|
+
const remainingBytes = item.size - position;
|
|
97
|
+
const currentChunkSize = Math.min(bodySize, remainingBytes);
|
|
98
|
+
fs.readFile({
|
|
99
|
+
filePath: item.tempFilePath || item.path,
|
|
100
|
+
encoding: "base64",
|
|
101
|
+
// 注意这里使用 'binary' 模式读取文件
|
|
102
|
+
position,
|
|
103
|
+
length: currentChunkSize,
|
|
104
|
+
success: (res) => {
|
|
105
|
+
console.log(res);
|
|
106
|
+
const buffer = res.data;
|
|
107
|
+
let fileReq = { tenant: this.properties.tenant, body: buffer, fileName: item.name, fileDir: "bigfile", fileSize: item.size, requestId, filePart: part };
|
|
108
|
+
fileApi.uploadWebFile(fileReq).then((res2) => {
|
|
109
|
+
console.log(res2);
|
|
110
|
+
this.setData({
|
|
111
|
+
percentage: Math.ceil(part * 100 / total)
|
|
112
|
+
});
|
|
113
|
+
if (Math.ceil(part * 100 / total) == 100) {
|
|
114
|
+
that.triggerEvent("getFileResponse", { fileResponse: res2.data, item });
|
|
115
|
+
}
|
|
116
|
+
if (part * bodySize < item.size) {
|
|
117
|
+
this.updateWebFilePart(fs, item, requestId, bodySize, ++part, total);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
fail: (err) => {
|
|
122
|
+
console.error("Failed to read file:", err);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<button class="file-btn" bindtap="chooseFileModel" style="{{ fileStyle }}">上传附件</button>
|
|
2
|
+
|
|
3
|
+
<van-progress wx:if="{{ percentage < 100 }}" percentage="{{ percentage }}" />
|
|
4
|
+
|
|
5
|
+
<auth-popup show="{{ closeModel }}" titleShow="{{ false }}">
|
|
6
|
+
<view class="item" bind:tap="handleUploadFile">微信</view>
|
|
7
|
+
<view class="item" bind:tap="handleAlbumImg">相册</view>
|
|
8
|
+
</auth-popup>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.file-btn{color:#fff;font-size:24rpx;width:100px !important;margin-bottom:16rpx}.item{font-size:28rpx;text-align:center;padding:12px 0;border-bottom:1px solid #ebebeb;font-size:16px}.item:nth-child(2){border-bottom:0;margin-bottom:40rpx}
|