123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import { baseUrl, tenantId, apiPath } from '@/utils/config'
- // const uploadApi = {
- // file: '/menduner/system/file/upload',
- // img: '/infra/file/upload'
- // }
- // 文件上传
- export const uploadFile = (file, path) => {
- uni.showLoading({
- title: '上传中'
- })
- return new Promise((resolve, reject) => {
- uni.uploadFile({
- url: baseUrl + apiPath + '/menduner/system/file/upload',
- filePath: file,
- formData: {
- path
- },
- name: 'file',
- header: {
- Accept: '*/*',
- 'tenant-id': tenantId,
- 'Authorization': 'Bearer ' + uni.getStorageSync('token'),
- 'Accept-Language': 'zh_CN',
- 'terminal': 'mp-weixin'
- },
- success: (uploadFileRes) => {
- let result = JSON.parse(uploadFileRes.data)
- if (result.error === 1) {
- uni.showToast({
- icon: 'none',
- title: result.msg
- })
- } else {
- return resolve(result)
- }
- },
- fail: (error) => {
- console.log('上传失败:', error)
- return resolve(false)
- },
- complete: () => {
- uni.hideLoading()
- }
- })
- })
- }
|