|
|
@@ -17,12 +17,28 @@ Component({
|
|
|
delete: {
|
|
|
type: Boolean
|
|
|
},
|
|
|
- deleteCallBack: {
|
|
|
+ onDeteleFiles: {
|
|
|
type: Function
|
|
|
+ },
|
|
|
+ padding: {
|
|
|
+ type: String,
|
|
|
+ value: '0 30rpx'
|
|
|
+ },
|
|
|
+ strict: {
|
|
|
+ type: Boolean
|
|
|
+ },
|
|
|
+ attinfos: {
|
|
|
+ type: Array
|
|
|
+ }
|
|
|
+ },
|
|
|
+ observers: {
|
|
|
+ 'attinfos': function (attinfos) {
|
|
|
+ this.initData();
|
|
|
+ this.handleFiles(attinfos, true)
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- /* 预览媒体 */
|
|
|
+ /* 预览媒体 */
|
|
|
viewMedias(e) {
|
|
|
const {
|
|
|
index,
|
|
|
@@ -33,7 +49,7 @@ Component({
|
|
|
sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
|
|
|
})
|
|
|
},
|
|
|
- /* 预览文档 */
|
|
|
+ /* 预览文档 */
|
|
|
viewFlies(e) {
|
|
|
const {
|
|
|
item
|
|
|
@@ -64,37 +80,54 @@ Component({
|
|
|
},
|
|
|
/* 删除文件 */
|
|
|
handleDeleteFile(e) {
|
|
|
- let item = e.currentTarget.dataset.item || e.currentTarget.dataset.item;
|
|
|
- _Http.basic({
|
|
|
- "classname": "system.attachment.Attachment",
|
|
|
- "method": "deleteFileLink",
|
|
|
- "content": {
|
|
|
- "linksids": [item.linksid]
|
|
|
- }
|
|
|
- }).then(res => {
|
|
|
- if (res.code != '1') return wx.showToast({
|
|
|
- title: res.msg,
|
|
|
- icon: "none"
|
|
|
+ let that = this;
|
|
|
+ if (this.data.strict) {
|
|
|
+ wx.showModal({
|
|
|
+ title: getApp().globalData.Language.getMapText('提示'),
|
|
|
+ content: getApp().globalData.Language.getMapText('是否确定删除该附件'),
|
|
|
+ cancelText: getApp().globalData.Language.getMapText('取消'),
|
|
|
+ confirmText: getApp().globalData.Language.getMapText('确定'),
|
|
|
+ complete: (res) => {
|
|
|
+ if (res.confirm) start()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ start()
|
|
|
+ }
|
|
|
+
|
|
|
+ function start() {
|
|
|
+ let item = e.currentTarget.dataset.item || e.currentTarget.dataset.item;
|
|
|
+ _Http.basic({
|
|
|
+ "classname": "system.attachment.Attachment",
|
|
|
+ "method": "deleteFileLink",
|
|
|
+ "content": {
|
|
|
+ "linksids": [item.linksid]
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ if (res.code != '1') return wx.showToast({
|
|
|
+ title: res.data,
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ let files = that.data.files;
|
|
|
+ switch (item.fileType) {
|
|
|
+ case "image":
|
|
|
+ files.images = files.images.filter(v => v.url != item.url);
|
|
|
+ files.viewImages = files.viewImages.filter(v => v.url != item.url);
|
|
|
+ break;
|
|
|
+ case "video":
|
|
|
+ files.videos = files.videos.filter(v => v.url != item.url);
|
|
|
+ files.viewVideos = files.viewVideos.filter(v => v.url != item.url);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ files.files = files.files.filter(v => v.attachmentid != item.attachmentid);
|
|
|
+ break;
|
|
|
+ };
|
|
|
+ that.setData({
|
|
|
+ files
|
|
|
+ });
|
|
|
+ that.triggerEvent("onDeteleFiles", that.getFiles())
|
|
|
});
|
|
|
- let files = this.data.files;
|
|
|
- switch (item.fileType) {
|
|
|
- case "image":
|
|
|
- files.images = files.images.filter(v => v.url != item.url);
|
|
|
- files.viewImages = files.viewImages.filter(v => v.url != item.url);
|
|
|
- break;
|
|
|
- case "video":
|
|
|
- files.videos = files.videos.filter(v => v.url != item.url);
|
|
|
- files.viewVideos = files.viewVideos.filter(v => v.url != item.url);
|
|
|
- break;
|
|
|
- default:
|
|
|
- files.files = files.files.filter(v => v.attachmentid != item.attachmentid);
|
|
|
- break;
|
|
|
- };
|
|
|
- this.setData({
|
|
|
- files
|
|
|
- });
|
|
|
- this.triggerEvent("deleteCallBack")
|
|
|
- })
|
|
|
+ }
|
|
|
},
|
|
|
/* 处理附件 */
|
|
|
handleFiles(arr, init = false) {
|
|
|
@@ -144,5 +177,42 @@ Component({
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ /* 返回数据ID数组 用来换绑数据 */
|
|
|
+ getFiles() {
|
|
|
+ let data = {
|
|
|
+ attachmentids: [],
|
|
|
+ list: [],
|
|
|
+ },
|
|
|
+ files = this.data.files;
|
|
|
+ files.files.forEach(v => {
|
|
|
+ data.attachmentids.push(v.attachmentid);
|
|
|
+ data.list.push(v);
|
|
|
+ })
|
|
|
+ files.images.forEach(v => {
|
|
|
+ data.attachmentids.push(v.attachmentid);
|
|
|
+ data.list.push(v);
|
|
|
+ })
|
|
|
+ files.videos.forEach(v => {
|
|
|
+ data.attachmentids.push(v.attachmentid);
|
|
|
+ data.list.push(v);
|
|
|
+ });
|
|
|
+ return data
|
|
|
+ },
|
|
|
+ deleteAll() {
|
|
|
+ let linksids = this.getFiles().list.map(v => v.linksid);
|
|
|
+ if (linksids.length) _Http.basic({
|
|
|
+ "classname": "system.attachment.Attachment",
|
|
|
+ "method": "deleteFileLink",
|
|
|
+ "content": {
|
|
|
+ linksids
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log("删除所有未保存附件", linksids, res)
|
|
|
+ if (res.code != '1') return wx.showToast({
|
|
|
+ title: res.data,
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
})
|