如何实现电脑登录小程序上传本地文件?
chooseFile: function () {
const that = this;
const deviceInfo = wx.getDeviceInfoSync?.() || {};
const isPC =
["windows", "mac", "desktop"].includes(deviceInfo.platform) ||
deviceInfo.deviceType === "desktop";
if (isPC) {
wx.chooseFile({
count: 9 - that.data.uploadFiles.length,
success: function (res) {
that.setData({
uploadFiles: [
...that.data.uploadFiles,
...res.tempFiles.map((file) => ({
path: file.path,
name: file.name.split("/").pop(),
type: file.type || "unknown",
})),
],
});
},
});
} else {
// 手机端选择微信文件
wx.chooseMessageFile({
count: 9 - that.data.uploadFiles.length,
type: "all",
success: function (res) {
that.setData({
uploadFiles: [
...that.data.uploadFiles,
...res.tempFiles.map((file) => ({
path: file.path,
name: file.name,
type: file.type || "unknown",
})),
],
});
},
});
}
},