| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import {
- ACCESS_TOKEN,
- USER_NAME,
- USER_INFO
- } from "@/common/util/constants" // 拉取登录token,userName,userInfo
- import http from '@/common/service/http.js'
- function uploaditem(item) {
- let token = uni.getStorageSync(ACCESS_TOKEN)
- return new Promise((resolve, reject) => {
- const path = item
- uni.uploadFile({
- // url: http.apiHosp + 'ibps/platform/v3/file/upload/mobile', //仅为示例,非真实的接口地址
- url: http.apiHosp + '/ibps/platform/v3/file/upload', //仅为示例,非真实的接口地址
- filePath: path,
- name: 'file',
- formData: {
- 'ext': '.jpg'
- },
- header: {
- 'X-Authorization-access_token': token,
- 'X-Authorization-systemid': ''
- },
- success: (uploadFileRes) => {
- let data = JSON.parse(uploadFileRes.data)
- let obj = {
- id: data.data.id,
- name: data.data.fileName + '.' + data.data.ext,
- ext: data.data.ext,
- uuid: data.data.id
- }
- resolve(obj)
- }
- })
- })
- }
- function selectUpload(file) {
- return new Promise((resolve, reject) => {
- let list = []
- //读取文件大小
- var fileSize = file.size;
- if (fileSize > 1048576) {
- that.$message({
- type: 'error',
- showClose: true,
- duration: 3000,
- message: '文件大于1M!'
- });
- return
- }
- let that = this
- let eList = []
- file.tempFilePaths.forEach(item => {
- eList.push(uploaditem(item))
- })
- Promise.all(eList).then((res3) => {
- resolve(res3)
- })
- })
- }
- function getFilesList(ids, that = this) {
- return new Promise((resolve, reject) => {
- let lists = ids.split(",")
- let params = {}
- params.ids = lists
- that.$http.post("/ibps/platform/v3/file/attachment/transfer", params).then(res => {
- if (res.data.state == 200) {
- const data = res.data.data
- let list = []
- lists.forEach(item => {
- let obj = {
- id: item,
- name: data[item].fileName + '.' + data[item].ext,
- ext: data[item].ext,
- uuid: item
- }
- list.push(obj)
- })
- resolve(list)
- }
- })
- })
- }
- export default {
- getFilesList,
- selectUpload
- }
|