diff --git a/common/api.js b/common/api.js index f8587aa..8ef6e95 100644 --- a/common/api.js +++ b/common/api.js @@ -30,15 +30,3 @@ export function listWaitingReleaseRooms() { method: "get", }); } - -// 上传文件 -export function uploadFile(data) { - return request({ - url: '/common/upload', - method: 'post', - data: data, - headers: { - 'Content-Type': 'multipart/form-data' - } - }) -} \ No newline at end of file diff --git a/pages/login/login.vue b/pages/login/login.vue index 0128129..ac2ba5e 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -73,8 +73,8 @@ export default { data() { return { form: { - username: "", - password: "", + username: "admin", + password: "!Aa12345", code: "", uuid: "", rememberMe: false, diff --git a/pages/tabBar/xjPage/xj.vue b/pages/tabBar/xjPage/xj.vue index c39ec46..1ad2f97 100644 --- a/pages/tabBar/xjPage/xj.vue +++ b/pages/tabBar/xjPage/xj.vue @@ -79,10 +79,11 @@ import { } from "@/common/rec"; import { getdeptList,addInspection,uploadFile } from '@/common/api.js'; import { getDicts } from "@/common/system/dict/data"; +import { baseUrl } from "@/utils/config"; export default { data () { return { - uploadUlr: 'http://219.146.91.110:30801/mz-api/common/upload', + uploadUlr: baseUrl + '/common/upload', wtlxShow: false, lysqShow: false, deptOptions: [], @@ -115,19 +116,16 @@ export default { }, methods: { afterRead(event) { - let files = Array.isArray(event) ? event : [event] + let files = Array.isArray(event) ? event.file : [event.file] this.fileList = this.fileList.concat(files) - event.file.forEach(item=>{ - this.form.imageList.push({ - url:item.url, - name: '', - format: item.type - }) - }) - console.log(this.form.imageList); + // console.log(this.fileList); + this.fileList.forEach( item => { + this.uploadFile(item[0]) + }); }, onDelete(event) { this.fileList.splice(event.index, 1) + this.form.imageList.splice(event.index, 1) }, getDictType(){ getDicts('inspection_question_type').then((res) => { @@ -163,25 +161,49 @@ export default { }, uploadFile(file){ - uploadFile(file).then((res) => { - console.log(res); - }); + let that = this + console.log('uploadFile',file); + uni.uploadFile({ + url: this.uploadUlr, + filePath: file.url, + name: 'file', //对应后台接口参数名 + method: 'post', + header: { + "Authorization": uni.getStorageSync('token') + }, + formData: { + //要上传的文件 + file: file + }, + success(res) { + let data = JSON.parse(res.data) + console.log(data); + if (data.url) { + that.form.imageList.push({ + url:data.url, + name: '', + format: file.type + }) + } + }, + fail(res) { + uni.showToast({ + icon: 'error', + title: '图片上传失败!' + }) + } + }) }, handleBtn () { - console.log(this.form); + // console.log(this.form); let parmas = JSON.parse(JSON.stringify(this.form)) - this.fileList.forEach(item => { - // parmas.imageList.push({ - // url:item.file.url, - // name: '', - // format: item.file.type - // }) - this.uploadFile(item.file) - }); delete parmas.apartmentName delete parmas.questionName addInspection(parmas).then(res=>{ - console.log(res); + uni.showToast({ + icon: 'success', + title: '提交成功!' + }) }) }, handleTreeSelect (e) {