Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(upload): enable to select media on iOS #239

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/upload/upload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isObject, SuperComponent, wxComponent } from '../common/src/index';
import props from './props';
import { MediaType, UploadMpConfig, UploadFile } from './type';
import { UploadMpConfig, UploadFile } from './type';
import config from '../common/config';

const { prefix } = config;
Expand All @@ -20,7 +20,6 @@ export default class Upload extends SuperComponent {
proofs: [],
customFiles: [] as UploadFile[], // 内部动态修改的files
customLimit: 0, // 内部动态修改的limit
mediaType: [] as MediaType[], // 这里由于小程序api问题目前不支持同时上传视频和图片
// 以下是声明properties
config: {} as UploadMpConfig,
files: [] as UploadFile[],
Expand Down Expand Up @@ -106,7 +105,7 @@ export default class Upload extends SuperComponent {
chooseImg() {
const { config, max, sizeLimit } = this.data;
wx.chooseMedia({
count: max,
count: max === 0 ? 9 : max, // 在 iOS 里,0 是无效的,会导致抛异常
mediaType: ['image'],
...config,
success: (res) => {
Expand All @@ -129,7 +128,7 @@ export default class Upload extends SuperComponent {
});
this._trigger('select-change', {
files: [...this.data.customFiles],
currentSelectedFiles: [files]
currentSelectedFiles: [files],
});
this._trigger('add', { files });
this._trigger('success', { files: [...this.data.customFiles, ...files] });
Expand Down Expand Up @@ -172,7 +171,7 @@ export default class Upload extends SuperComponent {
});
this._trigger('select-change', {
files: [...this.data.customFiles],
currentSelectedFiles: [files]
currentSelectedFiles: [files],
});
this._trigger('add', { files });
this._trigger('success', { files: [...this.data.customFiles, ...files] });
Expand All @@ -191,17 +190,15 @@ export default class Upload extends SuperComponent {
getRandFileName(filePath) {
const extIndex = filePath.lastIndexOf('.');
const extName = extIndex === -1 ? '' : filePath.substr(extIndex);
return (
parseInt(`${Date.now()}${Math.floor(Math.random() * 900 + 100)}`, 10).toString(36) + extName
);
return parseInt(`${Date.now()}${Math.floor(Math.random() * 900 + 100)}`, 10).toString(36) + extName;
}

closePop() {
this.setData({ showPop: false });
}

onAddTap() {
const { mediaType } = this.data;
const { mediaType } = this.properties;
// if (mediaType.length > 1) {
// this.setData({ showPop: true });
// return;
Expand Down