1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import create from 'dd-store'
import exampleStore from '/stores/exampleStore'
import { saveFileInfo, addSchedule, uploadPermissions, previewPermissions } from '../../api/request.js'
create.Page({
store: exampleStore,
useAll: true,
data: {
scheduleItem: '',
upLoadInfo: '',
descript: '',
uploadSpaceId: ''
},
onLoad(event) {
let scheduleItem = JSON.parse(event.scheduleItem)
let upLoadInfo = JSON.parse(decodeURIComponent(event.upLoadInfo))
this.setData({
scheduleItem: scheduleItem,
upLoadInfo: upLoadInfo
})
dd.setNavigationBar({
title: '上传文件'
})
},
onShow() {
},
inputDes(event) {
let value = event.detail.value
this.setData({
descript: value
})
},
close(event) {
let fileId = event.target.dataset.item.fileId
this.data.upLoadInfo.data.forEach((item, index) => {
if (item.fileId == fileId) {
this.data.upLoadInfo.data.splice(index, 1)
return
}
})
this.setData({
upLoadInfo: this.data.upLoadInfo
})
},
add() {
uploadPermissions().then(res => {
this.setData({
uploadSpaceId: res.data.data
})
const _that = this
dd.uploadAttachmentToDingTalk({
image: { multiple: true, compress: false, max: 9, spaceId: this.data.uploadSpaceId },
space: { spaceId: this.data.uploadSpaceId, max: 9 },
file: { spaceId: this.data.uploadSpaceId, max: 9 },
types: ["photo", "camera", "space"],//PC端仅支持["photo","file","space"]
success: (res) => {
_that.data.upLoadInfo.data.push(...res.data)
_that.setData({
upLoadInfo: _that.data.upLoadInfo
})
},
fail: (err) => {
}
})
})
},
// 点击保存
save() {
if (!!this.data.scheduleItem.id) {
this.saveUpload(this.data.scheduleItem.id)
} else {
let getId = {
scheduleTemplateId: this.data.scheduleItem.scheduleTemplateId,
planDate: this.data.scheduleItem.planDate,
createModel: 'auto'
}
addSchedule(getId).then(success => {
this.data.saveUpload(success.data.id)
})
}
},
// 保存的接口
saveUpload(id) {
let data = {
scheduleId: id,
uploader: getApp().globalData.userid,
uploaderInfo: JSON.stringify({
userId: getApp().globalData.userid,
username: getApp().globalData.name,
headUrl: getApp().globalData.avatar
}),
thirdStoreTenant: 'dingTalk',
fileInfos: JSON.stringify(this.data.upLoadInfo.data),
descript: this.data.descript
}
saveFileInfo(data).then(res => {
dd.navigateBack({
delta: 1
})
})
}
});