上传文件限制大小
This commit is contained in:
		
							
								
								
									
										1
									
								
								app.js
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								app.js
									
									
									
									
									
								
							| @@ -8,7 +8,6 @@ App({ | |||||||
|   onLaunch() { |   onLaunch() { | ||||||
|     const { api } = getConfigByEnv(); |     const { api } = getConfigByEnv(); | ||||||
|     this.globalData = { ...this.globalData, api, } |     this.globalData = { ...this.globalData, api, } | ||||||
|     |  | ||||||
|   }, |   }, | ||||||
|   globalData: { |   globalData: { | ||||||
|     primaryColor: '#52c41a' |     primaryColor: '#52c41a' | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ | |||||||
|     <view class="page-mask" bindtap="hidePagePopup"></view> |     <view class="page-mask" bindtap="hidePagePopup"></view> | ||||||
|     <view class="page-popup"> |     <view class="page-popup"> | ||||||
|       <view class="page-popup-box"> |       <view class="page-popup-box"> | ||||||
|         <view class="page-line" wx:for="{{total}}" wx:for-index="idx" data-index="{{idx+1}}" bindtap="changePage">第{{item+1}}页</view> |         <view class="page-line" wx:for="{{total}}" wx:key="index" wx:for-index="idx" data-index="{{idx+1}}" bindtap="changePage">第{{item+1}}页</view> | ||||||
|       </view> |       </view> | ||||||
|     </view> |     </view> | ||||||
|   </view> |   </view> | ||||||
|   | |||||||
| @@ -39,6 +39,7 @@ Page({ | |||||||
|     }) |     }) | ||||||
|   }, |   }, | ||||||
|   async upload(res) { |   async upload(res) { | ||||||
|  |      | ||||||
|     const result = await uploadPublicFile(res.tempFiles[0]?.tempFilePath) |     const result = await uploadPublicFile(res.tempFiles[0]?.tempFilePath) | ||||||
|     if (result.statusCode !== 200) { |     if (result.statusCode !== 200) { | ||||||
|       alertInfo("上传失败") |       alertInfo("上传失败") | ||||||
| @@ -55,6 +56,12 @@ Page({ | |||||||
|       mediaType: ['image'], // 可以选择文件的类型,这里只允许上传文件   |       mediaType: ['image'], // 可以选择文件的类型,这里只允许上传文件   | ||||||
|       sourceType: ['album', 'camera'], |       sourceType: ['album', 'camera'], | ||||||
|       success: (res) => { |       success: (res) => { | ||||||
|  |         const file = res.tempFiles[0]; | ||||||
|  |         if (file.size / 1024 / 1024 > 1) { | ||||||
|  |           alertInfo("文件不能大于1M") | ||||||
|  |           return; | ||||||
|  |         } | ||||||
|  |         // console.log('res', res) | ||||||
|         loadingFunc(async () => { |         loadingFunc(async () => { | ||||||
|           await this.upload(res) |           await this.upload(res) | ||||||
|         }) |         }) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user