|
@@ -1,5 +1,5 @@
|
|
|
import api from '../../api/api.js'
|
|
|
-
|
|
|
+let waitBindings = []; //等待绑定的附件
|
|
|
Component({
|
|
|
/**
|
|
|
* 组件的属性列表
|
|
@@ -19,47 +19,91 @@ Component({
|
|
|
value: wx.getStorageSync('siteP').appfolderid
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
- /**
|
|
|
- * 组件的初始数据
|
|
|
- */
|
|
|
data: {
|
|
|
originFiles: [],
|
|
|
- filelist: [],
|
|
|
- attachmentids: [],
|
|
|
gridConfig: {
|
|
|
column: 5,
|
|
|
width: 120,
|
|
|
height: 120,
|
|
|
- },
|
|
|
- config: {
|
|
|
- count: 1,
|
|
|
- },
|
|
|
- timer: null,
|
|
|
- uploadCount: 0
|
|
|
+ }
|
|
|
},
|
|
|
lifetimes: {
|
|
|
attached() {
|
|
|
setTimeout(() => {
|
|
|
this.fileData()
|
|
|
}, 1000);
|
|
|
-
|
|
|
}
|
|
|
},
|
|
|
- /**
|
|
|
- * 组件的方法列表
|
|
|
- */
|
|
|
methods: {
|
|
|
handleAdd(file) {
|
|
|
- let files = this.data.originFiles.concat(file.detail.files.map(e => {
|
|
|
+ this.toSetFileData(file.detail.files.map(e => {
|
|
|
e.status = 'loading'
|
|
|
return e
|
|
|
- }));
|
|
|
+ }))
|
|
|
+ },
|
|
|
+ toSetFileData(files) {
|
|
|
this.setData({
|
|
|
- uploadCount: files.length,
|
|
|
- originFiles: files
|
|
|
+ originFiles: this.data.originFiles.concat(files)
|
|
|
+ })
|
|
|
+ for (let i = 0; i < files.length; i++) {
|
|
|
+ // 初始化数据
|
|
|
+ let that = this,
|
|
|
+ data = this.requestType(files[i]);
|
|
|
+ data.content.filename = data.content.filename ? data.content.filename : `${Date.now()}.${data.content.filetype}`;
|
|
|
+ //发送请求
|
|
|
+ wx.getFileSystemManager().readFile({
|
|
|
+ filePath: files[i].url,
|
|
|
+ success: result => {
|
|
|
+ //返回临时文件路径
|
|
|
+ const fileData = result.data;
|
|
|
+ api._post(data).then(res => {
|
|
|
+ console.log("文件上传", res)
|
|
|
+ if (res.msg == "成功") {
|
|
|
+ that.uploadFile(res.data, fileData, files.length);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail: console.error
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /* 上传成功反馈 */
|
|
|
+ uploadFile(res, data, count) {
|
|
|
+ var that = this;
|
|
|
+ wx.request({
|
|
|
+ url: res.uploadurl,
|
|
|
+ method: "PUT",
|
|
|
+ data: data,
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/octet-stream'
|
|
|
+ },
|
|
|
+ success(a) {
|
|
|
+ api._post({
|
|
|
+ "classname": "system.attachment.huawei.OBS",
|
|
|
+ "method": "uploadSuccess",
|
|
|
+ "content": {
|
|
|
+ "serialfilename": res.serialfilename
|
|
|
+ }
|
|
|
+ }).then(rs => {
|
|
|
+ console.log('上传成功反馈', rs)
|
|
|
+ waitBindings.push(rs.data.attachmentids[0] || "");
|
|
|
+ let data = that.data.originFiles.find(e => e.name === res.filename);
|
|
|
+ if (data) {
|
|
|
+ data.status = '';
|
|
|
+ data.attachmentids = rs.data.attachmentids[0]
|
|
|
+ }
|
|
|
+ if (waitBindings.length == count) {
|
|
|
+ that.filebindData();
|
|
|
+ that.setData({
|
|
|
+ originFiles: that.data.originFiles
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ }).catch(err => {
|
|
|
+ console.log(err)
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
- this.toSetFileData()
|
|
|
},
|
|
|
handleClick() {
|
|
|
let that = this
|
|
@@ -92,37 +136,6 @@ Component({
|
|
|
}
|
|
|
this.deleteFile(file)
|
|
|
},
|
|
|
- toSetFileData() {
|
|
|
-
|
|
|
- let files = this.data.originFiles
|
|
|
-
|
|
|
- for (let i = 0; i < files.length; i++) {
|
|
|
- // 初始化数据
|
|
|
- let that = this,
|
|
|
- data = this.requestType(files[i]);
|
|
|
- data.content.filename = data.content.filename ? data.content.filename : `${Date.now()}.${data.content.filetype}`;
|
|
|
- //发送请求
|
|
|
- wx.getFileSystemManager().readFile({
|
|
|
- filePath: files[i].url,
|
|
|
- success: result => {
|
|
|
- //返回临时文件路径
|
|
|
- const fileData = result.data;
|
|
|
- api._post(data).then(res => {
|
|
|
- if (res.msg == "成功") {
|
|
|
- that.uploadFile(res.data, fileData)
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- fail: console.error
|
|
|
- })
|
|
|
- }
|
|
|
- this.data.timer = setInterval(e => {
|
|
|
- if (this.data.uploadCount === 0) {
|
|
|
- clearInterval(this.data.timer)
|
|
|
- this.filebindData()
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
/* 请求类型 */
|
|
|
requestType(file) {
|
|
|
var index = file.url.lastIndexOf(".");
|
|
@@ -138,49 +151,17 @@ Component({
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- /* 上传成功反馈 */
|
|
|
- uploadFile(res, data) {
|
|
|
- var that = this;
|
|
|
- wx.request({
|
|
|
- url: res.uploadurl,
|
|
|
- method: "PUT",
|
|
|
- data: data,
|
|
|
- header: {
|
|
|
- 'content-type': 'application/octet-stream'
|
|
|
- },
|
|
|
- success(a) {
|
|
|
- api._post({
|
|
|
- "classname": "system.attachment.huawei.OBS",
|
|
|
- "method": "uploadSuccess",
|
|
|
- "content": {
|
|
|
- "serialfilename": res.serialfilename
|
|
|
- }
|
|
|
- }).then(rs => {
|
|
|
- that.data.attachmentids.push(rs.data.attachmentids[0])
|
|
|
- that.setData({
|
|
|
- uploadCount: that.data.uploadCount - 1,
|
|
|
- originFiles: that.data.originFiles.map(e => {
|
|
|
- if (e.name === res.filename) {
|
|
|
- e.status = '';
|
|
|
- e.attachmentids = rs.data.attachmentids[0]
|
|
|
- }
|
|
|
- return e
|
|
|
- })
|
|
|
- })
|
|
|
- }).catch(err => {
|
|
|
- console.log(err)
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
async filebindData() {
|
|
|
- this.data.bindData.attachmentids = this.data.attachmentids
|
|
|
+ this.data.bindData.attachmentids = JSON.parse(JSON.stringify(waitBindings));
|
|
|
const res = await api._post({
|
|
|
"classname": "system.attachment.Attachment",
|
|
|
"method": "createFileLink",
|
|
|
"content": this.data.bindData
|
|
|
})
|
|
|
+ console.log("绑定", res)
|
|
|
+ if (res.msg != '成功') return;
|
|
|
this.fileData()
|
|
|
+ waitBindings = [];
|
|
|
},
|
|
|
async fileData() {
|
|
|
const res = await api._post({
|
|
@@ -188,9 +169,10 @@ Component({
|
|
|
"method": "queryFileLink",
|
|
|
"content": this.data.bindData
|
|
|
})
|
|
|
+ console.log('获取文件', res)
|
|
|
this.setData({
|
|
|
originFiles: res.data
|
|
|
- })
|
|
|
+ });
|
|
|
},
|
|
|
async deleteFile(data) {
|
|
|
let item = data.currentTarget.dataset.item
|