askbot-dragon 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +27 -27
  2. package/babel.config.js +6 -6
  3. package/dragon.iml +7 -7
  4. package/package.json +56 -56
  5. package/public/index.html +43 -43
  6. package/src/App.vue +31 -31
  7. package/src/api/index.js +1 -1
  8. package/src/api/mock.http +2 -2
  9. package/src/api/requestUrl.js +185 -185
  10. package/src/assets/js/AliyunlssUtil.js +92 -92
  11. package/src/assets/js/Base64Util.js +22 -22
  12. package/src/assets/js/script.js +36 -36
  13. package/src/assets/less/common.css +6773 -6773
  14. package/src/assets/less/converSationContainer/common.less +191 -191
  15. package/src/assets/less/converSationContainer/converSatonContainer.less +493 -493
  16. package/src/assets/less/iconfont.css +37 -37
  17. package/src/assets/less/ticketMessage.less +211 -211
  18. package/src/components/ActionAlertIframe.vue +112 -112
  19. package/src/components/AiGuide.vue +467 -467
  20. package/src/components/AskIFrame.vue +15 -15
  21. package/src/components/ConversationContainer.vue +4617 -4617
  22. package/src/components/FileType.vue +86 -86
  23. package/src/components/Message.vue +27 -27
  24. package/src/components/actionSatisfaction.vue +107 -107
  25. package/src/components/actionSendToBot.vue +62 -62
  26. package/src/components/answerDissatisfaction.vue +62 -62
  27. package/src/components/answerRadio.vue +76 -76
  28. package/src/components/ask-components/DissatisfactionOptions.vue +57 -57
  29. package/src/components/ask-components/Msgloading.vue +37 -37
  30. package/src/components/ask-components/SatisfactionV2.vue +15 -15
  31. package/src/components/askVideo.vue +138 -138
  32. package/src/components/assetDetails.vue +370 -370
  33. package/src/components/assetMessage.vue +228 -228
  34. package/src/components/associationIntention.vue +258 -243
  35. package/src/components/botActionSatisfactor.vue +68 -68
  36. package/src/components/chatContent.vue +513 -513
  37. package/src/components/feedBack.vue +136 -136
  38. package/src/components/fielListView.vue +346 -346
  39. package/src/components/file/AliyunOssComponents.vue +108 -108
  40. package/src/components/formTemplate.vue +3344 -3344
  41. package/src/components/loadingProcess.vue +164 -164
  42. package/src/components/message/ActionAlertIframe.vue +112 -112
  43. package/src/components/message/ShopMessage.vue +164 -164
  44. package/src/components/message/TextMessage.vue +924 -924
  45. package/src/components/message/TicketMessage.vue +177 -177
  46. package/src/components/message/swiper/index.js +4 -4
  47. package/src/components/message/swiper/ticketSwiper.vue +503 -503
  48. package/src/components/message/swiper/ticketSwiperItem.vue +61 -61
  49. package/src/components/msgLoading.vue +231 -231
  50. package/src/components/myPopup.vue +70 -70
  51. package/src/components/popup.vue +227 -227
  52. package/src/components/receiverMessagePlatform.vue +65 -65
  53. package/src/components/recommend.vue +89 -89
  54. package/src/components/selector/hOption.vue +20 -20
  55. package/src/components/selector/hSelector.vue +199 -199
  56. package/src/components/selector/hWrapper.vue +216 -216
  57. package/src/components/senderMessagePlatform.vue +50 -50
  58. package/src/components/source/BotMessage.vue +24 -24
  59. package/src/components/source/CustomMessage.vue +24 -24
  60. package/src/components/test.vue +260 -260
  61. package/src/components/tree.vue +247 -247
  62. package/src/components/utils/AliyunIssUtil.js +72 -72
  63. package/src/components/utils/ckeditor.js +155 -155
  64. package/src/components/utils/ckeditorImageUpload/command.js +109 -109
  65. package/src/components/utils/ckeditorImageUpload/editing.js +11 -11
  66. package/src/components/utils/ckeditorImageUpload/plugin-image.js +11 -11
  67. package/src/components/utils/ckeditorImageUpload/toolbar-ui.js +40 -40
  68. package/src/components/utils/ckeditorfileUpload/common.js +111 -111
  69. package/src/components/utils/ckeditorfileUpload/editing.js +11 -11
  70. package/src/components/utils/ckeditorfileUpload/plugin_file.js +11 -11
  71. package/src/components/utils/ckeditorfileUpload/toolbar_ui.js +34 -34
  72. package/src/components/utils/format_date.js +25 -25
  73. package/src/components/utils/index.js +6 -6
  74. package/src/components/utils/math_utils.js +29 -29
  75. package/src/components/voiceComponent.vue +119 -119
  76. package/src/main.js +60 -60
  77. package/vue.config.js +47 -47
@@ -1,248 +1,248 @@
1
- <template>
2
- <div id="tree">
3
- <div class="tree-header">
4
- <span class="cacel" @click="cancelBtn">取消</span>
5
- <span class="primary" @click="saveData">确认</span>
6
- </div>
7
- <div class="tree-container">
8
- <el-tree :data="setCascadeOption"
9
- :props="defaultProps"
10
- ref="dataTree"
11
- node-key="value"
12
- >
13
- <span class="custom-tree-node" slot-scope="{ node,data}">
14
- <span class="tree-label">{{ node.label }}</span>
15
- <span>
16
- <el-checkbox v-model="data.checked" v-if="dataOptions.extInfo.selectType ==='多选'"></el-checkbox>
17
- <el-radio v-model="checked" v-else :label="data.value"></el-radio>
18
- </span>
19
- </span>
20
- </el-tree>
21
- </div>
22
- <!-- <div class="footer">
23
- <el-button>取 消</el-button>
24
- <el-button type="primary" @click="saveData">确 认</el-button>
25
- </div>-->
26
- </div>
27
- </template>
28
-
29
- <script>
30
- /* eslint-disable */
31
- export default {
32
- name: "tree",
33
- data(){
34
- return{
35
- defaultProps:{
36
- label:"label",
37
- value:"value"
38
- },
39
- checked:'',
40
- // dataTree:[],
41
- checkList:[],
42
- checkDatas:[]
43
- }
44
- },
45
- props:["dataOptions","fieldValue"],
46
- methods:{
47
- saveData(){
48
- this.checkList = []
49
- this.checkDatas = []
50
- this.ergodicData(this.setCascadeOption,this.checkList)
51
- this.$emit('saveData',this.checkList,this.checkDatas)
52
- },
53
- cancelBtn(){
54
- this.$emit('cancelBtn')
55
- },
56
- ergodicData(list){
57
- list.forEach(item=>{
58
- if (this.dataOptions.extInfo.selectType === '多选'){
59
- if (item.checked){
60
- let data = this.$refs.dataTree.getNode(item)
61
- let checkList = []
62
- let arr = this.serchParent(data,checkList)
63
- this.checkList.push(arr)
64
- this.checkDatas.push(item)
65
- }
66
- }
67
- else {
68
- if (item.value === this.checked){
69
- let data = this.$refs.dataTree.getNode(item)
70
- let checkList = []
71
- let arr = this.serchParent(data,checkList)
72
- this.checkList = arr
73
- this.checkDatas = [item]
74
- }
75
- }
76
- if (item.children){
77
- this.ergodicData(item.children)
78
- }
79
- })
80
- },
81
- serchParent(node,list) {
82
- if(node) {
83
- if(Object.prototype.toString.call(node.data) == '[object Object]') {
84
- list.unshift(node.data.value)
85
- }
86
- if(node.parent) {
87
- list = this.serchParent(node.parent,list)
88
- }
89
- }
90
- return list
91
- },
92
- },
93
- computed: {
94
- dataTree() {
95
- let arr = []
96
- if (this.dataOptions.extInfo.cascadeDown.options){
97
- arr = this.dataOptions.extInfo.cascadeDown.options
98
- }
99
- else if (this.dataOptions.extInfo.cascade){
100
- arr = this.dataOptions.extInfo.cascade
101
- }
102
- else if (this.dataOptions.extInfo.cascadeDown && this.dataOptions.extInfo.cascadeDown[0]){
103
- arr = this.dataOptions.extInfo.cascadeDown[0].options
104
- }
105
- return arr
106
- },
107
- //规则中限制极限的选项
108
- setCascadeOption(){
109
- let options = [];
110
- let arr = []
111
- if (this.dataOptions.extInfo && (this.dataOptions.extInfo.cascadeDown || this.dataOptions.extInfo.cascade)){
112
- arr = this.dataOptions.extInfo.cascadeDown.options ? this.dataOptions.extInfo.cascadeDown.options :
113
- (this.dataOptions.extInfo.cascadeDown[0] ? this.dataOptions.extInfo.cascadeDown[0].options :
114
- (this.dataOptions.extInfo.cascade ? this.dataOptions.extInfo.cascade: []));
115
- }
116
- if (this.dataOptions.extInfo && this.dataOptions.extInfo.dependent && JSON.stringify(this.dataOptions.extInfo.dependent)!=='{}'){
117
- for (let k in this.dataOptions.extInfo.dependent){
118
- if (Array.isArray(this.fieldValue[k]) && Array.isArray(this.fieldValue[k][0])){
119
- this.fieldValue[k].forEach(item=>{
120
- this.dataOptions.extInfo.dependent[k].filterStruct.forEach(filter=>{
121
- if (filter.input === item || item[item.length - 1] == filter.input){
122
- if (!options){
123
- options = []
124
- }
125
- options = options.concat(filter.output)
126
- }
127
- })
128
- })
129
- }
130
- else {
131
- console.log(this.dataOptions.extInfo.dependent[k].filterStruct);
132
- this.dataOptions.extInfo.dependent[k].filterStruct.forEach(filter=>{
133
- if (this.fieldValue[k] && (filter.input === this.fieldValue[k] || this.fieldValue[k][this.fieldValue[k].length - 1] == filter.input)){
134
- options = filter.output;
135
-
136
- }
137
- })
138
- }
139
- }
140
- const initCascade = (arr, parent)=>{
141
- return JSON.parse(JSON.stringify(arr)).filter(item =>{
142
- if (item.children){
143
- item.children = initCascade(item.children, item)
144
- }
145
- let flag = null
146
- for (let i = 0; i < options.length; i++) {
147
- const optArr = options[i];
148
- item.checked = false;
149
- if(optArr.indexOf(item.value) !== -1) {
150
- if(parent === null || item.children && item.children.length != 0) {
151
- flag = true
152
- } else if(parent && optArr.indexOf(parent.value) !== -1 &&
153
- (Math.abs(optArr.indexOf(parent.value) - optArr.indexOf(item.value)) === 1 )) {
154
- flag = true
155
- }
156
- }
157
- }
158
- return flag && item
159
- })
160
- }
161
- arr = initCascade(arr,null)
162
- }
163
- else {
164
- return arr
165
- }
166
- console.debug('options',arr)
167
- return arr
168
- },
169
- },
170
- // mounted() {
171
- // if (this.dataOptions.extInfo.cascadeDown.options){
172
- // debugger
173
- // this.dataTree = this.dataOptions.extInfo.cascadeDown.options
174
- // }
175
- // else if (this.dataOptions.extInfo.cascade){
176
- // this.dataTree = this.dataOptions.extInfo.cascade
177
- // }
178
- // else if (this.dataOptions.extInfo.cascadeDown && this.dataOptions.extInfo.cascadeDown[0]){
179
- // this.dataTree = this.dataOptions.extInfo.cascadeDown[0].options
180
- // }
181
- // console.debug('dataTree',this.dataOptions,this.dataTree)
182
- // }
183
- };
184
- </script>
185
-
186
- <style scoped lang="less">
187
- #tree{
188
- height: 100%;
189
- overflow: hidden;
190
- /deep/.el-tree-node__content{
191
- height: 38px;
192
- line-height: 38px;
193
- }
194
- .tree-header{
195
- height: 30px;
196
- display: flex;
197
- align-items: center;
198
- justify-content: space-between;
199
- margin: 0 20px;
200
- width: calc(100% - 40px);
201
- /*font-size: 14px;*/
202
- padding-bottom: 30px;
203
- .primary{
204
- color: #366aff;
205
- cursor: pointer;
206
- }
207
- .cacel{
208
- color: #969799;
209
- cursor: pointer;
210
- }
211
- }
212
- .tree-container{
213
- height:260px;
214
- overflow-y: scroll;
215
- overflow-x: hidden;
216
- }
217
- .custom-tree-node{
218
- display: flex;
219
- align-items: center;
220
- justify-content: space-between;
221
- width: calc(100% - 40px);
222
- font-size: 14px;
223
- .tree-label{
224
- max-width: 160px;
225
- overflow: hidden;
226
- text-overflow: ellipsis;
227
- white-space: nowrap;
228
- }
229
- /deep/.el-radio__label{
230
- display: none;
231
- }
232
- }
233
- .footer{
234
- position: absolute;
235
- bottom: 0;
236
- height: 60px;
237
- display: flex;
238
- align-items: center;
239
- justify-content: space-between;
240
- width: calc(100% - 40px);
241
- margin: 0 20px;
242
- .el-button{
243
- flex: 1;
244
- border-radius: 9px;
245
- }
246
- }
247
- }
1
+ <template>
2
+ <div id="tree">
3
+ <div class="tree-header">
4
+ <span class="cacel" @click="cancelBtn">取消</span>
5
+ <span class="primary" @click="saveData">确认</span>
6
+ </div>
7
+ <div class="tree-container">
8
+ <el-tree :data="setCascadeOption"
9
+ :props="defaultProps"
10
+ ref="dataTree"
11
+ node-key="value"
12
+ >
13
+ <span class="custom-tree-node" slot-scope="{ node,data}">
14
+ <span class="tree-label">{{ node.label }}</span>
15
+ <span>
16
+ <el-checkbox v-model="data.checked" v-if="dataOptions.extInfo.selectType ==='多选'"></el-checkbox>
17
+ <el-radio v-model="checked" v-else :label="data.value"></el-radio>
18
+ </span>
19
+ </span>
20
+ </el-tree>
21
+ </div>
22
+ <!-- <div class="footer">
23
+ <el-button>取 消</el-button>
24
+ <el-button type="primary" @click="saveData">确 认</el-button>
25
+ </div>-->
26
+ </div>
27
+ </template>
28
+
29
+ <script>
30
+ /* eslint-disable */
31
+ export default {
32
+ name: "tree",
33
+ data(){
34
+ return{
35
+ defaultProps:{
36
+ label:"label",
37
+ value:"value"
38
+ },
39
+ checked:'',
40
+ // dataTree:[],
41
+ checkList:[],
42
+ checkDatas:[]
43
+ }
44
+ },
45
+ props:["dataOptions","fieldValue"],
46
+ methods:{
47
+ saveData(){
48
+ this.checkList = []
49
+ this.checkDatas = []
50
+ this.ergodicData(this.setCascadeOption,this.checkList)
51
+ this.$emit('saveData',this.checkList,this.checkDatas)
52
+ },
53
+ cancelBtn(){
54
+ this.$emit('cancelBtn')
55
+ },
56
+ ergodicData(list){
57
+ list.forEach(item=>{
58
+ if (this.dataOptions.extInfo.selectType === '多选'){
59
+ if (item.checked){
60
+ let data = this.$refs.dataTree.getNode(item)
61
+ let checkList = []
62
+ let arr = this.serchParent(data,checkList)
63
+ this.checkList.push(arr)
64
+ this.checkDatas.push(item)
65
+ }
66
+ }
67
+ else {
68
+ if (item.value === this.checked){
69
+ let data = this.$refs.dataTree.getNode(item)
70
+ let checkList = []
71
+ let arr = this.serchParent(data,checkList)
72
+ this.checkList = arr
73
+ this.checkDatas = [item]
74
+ }
75
+ }
76
+ if (item.children){
77
+ this.ergodicData(item.children)
78
+ }
79
+ })
80
+ },
81
+ serchParent(node,list) {
82
+ if(node) {
83
+ if(Object.prototype.toString.call(node.data) == '[object Object]') {
84
+ list.unshift(node.data.value)
85
+ }
86
+ if(node.parent) {
87
+ list = this.serchParent(node.parent,list)
88
+ }
89
+ }
90
+ return list
91
+ },
92
+ },
93
+ computed: {
94
+ dataTree() {
95
+ let arr = []
96
+ if (this.dataOptions.extInfo.cascadeDown.options){
97
+ arr = this.dataOptions.extInfo.cascadeDown.options
98
+ }
99
+ else if (this.dataOptions.extInfo.cascade){
100
+ arr = this.dataOptions.extInfo.cascade
101
+ }
102
+ else if (this.dataOptions.extInfo.cascadeDown && this.dataOptions.extInfo.cascadeDown[0]){
103
+ arr = this.dataOptions.extInfo.cascadeDown[0].options
104
+ }
105
+ return arr
106
+ },
107
+ //规则中限制极限的选项
108
+ setCascadeOption(){
109
+ let options = [];
110
+ let arr = []
111
+ if (this.dataOptions.extInfo && (this.dataOptions.extInfo.cascadeDown || this.dataOptions.extInfo.cascade)){
112
+ arr = this.dataOptions.extInfo.cascadeDown.options ? this.dataOptions.extInfo.cascadeDown.options :
113
+ (this.dataOptions.extInfo.cascadeDown[0] ? this.dataOptions.extInfo.cascadeDown[0].options :
114
+ (this.dataOptions.extInfo.cascade ? this.dataOptions.extInfo.cascade: []));
115
+ }
116
+ if (this.dataOptions.extInfo && this.dataOptions.extInfo.dependent && JSON.stringify(this.dataOptions.extInfo.dependent)!=='{}'){
117
+ for (let k in this.dataOptions.extInfo.dependent){
118
+ if (Array.isArray(this.fieldValue[k]) && Array.isArray(this.fieldValue[k][0])){
119
+ this.fieldValue[k].forEach(item=>{
120
+ this.dataOptions.extInfo.dependent[k].filterStruct.forEach(filter=>{
121
+ if (filter.input === item || item[item.length - 1] == filter.input){
122
+ if (!options){
123
+ options = []
124
+ }
125
+ options = options.concat(filter.output)
126
+ }
127
+ })
128
+ })
129
+ }
130
+ else {
131
+ console.log(this.dataOptions.extInfo.dependent[k].filterStruct);
132
+ this.dataOptions.extInfo.dependent[k].filterStruct.forEach(filter=>{
133
+ if (this.fieldValue[k] && (filter.input === this.fieldValue[k] || this.fieldValue[k][this.fieldValue[k].length - 1] == filter.input)){
134
+ options = filter.output;
135
+
136
+ }
137
+ })
138
+ }
139
+ }
140
+ const initCascade = (arr, parent)=>{
141
+ return JSON.parse(JSON.stringify(arr)).filter(item =>{
142
+ if (item.children){
143
+ item.children = initCascade(item.children, item)
144
+ }
145
+ let flag = null
146
+ for (let i = 0; i < options.length; i++) {
147
+ const optArr = options[i];
148
+ item.checked = false;
149
+ if(optArr.indexOf(item.value) !== -1) {
150
+ if(parent === null || item.children && item.children.length != 0) {
151
+ flag = true
152
+ } else if(parent && optArr.indexOf(parent.value) !== -1 &&
153
+ (Math.abs(optArr.indexOf(parent.value) - optArr.indexOf(item.value)) === 1 )) {
154
+ flag = true
155
+ }
156
+ }
157
+ }
158
+ return flag && item
159
+ })
160
+ }
161
+ arr = initCascade(arr,null)
162
+ }
163
+ else {
164
+ return arr
165
+ }
166
+ console.debug('options',arr)
167
+ return arr
168
+ },
169
+ },
170
+ // mounted() {
171
+ // if (this.dataOptions.extInfo.cascadeDown.options){
172
+ // debugger
173
+ // this.dataTree = this.dataOptions.extInfo.cascadeDown.options
174
+ // }
175
+ // else if (this.dataOptions.extInfo.cascade){
176
+ // this.dataTree = this.dataOptions.extInfo.cascade
177
+ // }
178
+ // else if (this.dataOptions.extInfo.cascadeDown && this.dataOptions.extInfo.cascadeDown[0]){
179
+ // this.dataTree = this.dataOptions.extInfo.cascadeDown[0].options
180
+ // }
181
+ // console.debug('dataTree',this.dataOptions,this.dataTree)
182
+ // }
183
+ };
184
+ </script>
185
+
186
+ <style scoped lang="less">
187
+ #tree{
188
+ height: 100%;
189
+ overflow: hidden;
190
+ /deep/.el-tree-node__content{
191
+ height: 38px;
192
+ line-height: 38px;
193
+ }
194
+ .tree-header{
195
+ height: 30px;
196
+ display: flex;
197
+ align-items: center;
198
+ justify-content: space-between;
199
+ margin: 0 20px;
200
+ width: calc(100% - 40px);
201
+ /*font-size: 14px;*/
202
+ padding-bottom: 30px;
203
+ .primary{
204
+ color: #366aff;
205
+ cursor: pointer;
206
+ }
207
+ .cacel{
208
+ color: #969799;
209
+ cursor: pointer;
210
+ }
211
+ }
212
+ .tree-container{
213
+ height:260px;
214
+ overflow-y: scroll;
215
+ overflow-x: hidden;
216
+ }
217
+ .custom-tree-node{
218
+ display: flex;
219
+ align-items: center;
220
+ justify-content: space-between;
221
+ width: calc(100% - 40px);
222
+ font-size: 14px;
223
+ .tree-label{
224
+ max-width: 160px;
225
+ overflow: hidden;
226
+ text-overflow: ellipsis;
227
+ white-space: nowrap;
228
+ }
229
+ /deep/.el-radio__label{
230
+ display: none;
231
+ }
232
+ }
233
+ .footer{
234
+ position: absolute;
235
+ bottom: 0;
236
+ height: 60px;
237
+ display: flex;
238
+ align-items: center;
239
+ justify-content: space-between;
240
+ width: calc(100% - 40px);
241
+ margin: 0 20px;
242
+ .el-button{
243
+ flex: 1;
244
+ border-radius: 9px;
245
+ }
246
+ }
247
+ }
248
248
  </style>
@@ -1,72 +1,72 @@
1
- const OSS = require('ali-oss');
2
-
3
- let IDX = 256, HEX = [], SIZE = 256, BUFFER;
4
- while (IDX--) HEX[IDX] = (IDX + 256).toString(16).substring(1);
5
- let mainId = sessionStorage.getItem('_mainId') ? sessionStorage.getItem('_mainId') : "";
6
- function uid(len) {
7
- let i = 0, tmp = (len || 11);
8
- if (!BUFFER || ((IDX + tmp) > SIZE * 2)) {
9
- for (BUFFER = '', IDX = 0; i < SIZE; i++) {
10
- BUFFER += HEX[Math.random() * 256 | 0];
11
- }
12
- }
13
-
14
- return BUFFER.substring(IDX, IDX++ + tmp);
15
- }
16
-
17
- function dataFormat(fmt, date = new Date()) {
18
- const o = {
19
- "M+": date.getMonth() + 1, //月份
20
- "d+": date.getDate(), //日
21
- "h+": date.getHours(), //小时
22
- "m+": date.getMinutes(), //分
23
- "s+": date.getSeconds(), //秒
24
- "q+": Math.floor((date.getMonth() + 3) / 3), //季度
25
- "S": date.getMilliseconds() //毫秒
26
- };
27
- if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
28
- for (const k in o)
29
- if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
30
- return fmt;
31
- }
32
-
33
- function pathGenerate(filename) {
34
- return "front-oss/" + mainId + '/' + dataFormat("yyyy/MM/dd/hh/mm/") + uid(32) + "/" + filename;
35
- }
36
-
37
-
38
- function upload(ossConfig, data) {
39
- let ossClient = new OSS(ossConfig);
40
- // object-key可以自定义为文件名(例如file.txt)或目录(例如abc/test/file.txt)的形式,实现将文件上传至当前Bucket或Bucket下的指定目录。
41
- let objectKey = pathGenerate(data.name);
42
- let result = ossClient.put(objectKey, data);
43
- console.debug(result);
44
- return result;
45
- }
46
-
47
- function multipartUpload(ossConfig, data, callback,extCallback) {
48
- let ossClient = new OSS(ossConfig);
49
- // object-key可以自定义为文件名(例如file.txt)或目录(例如abc/test/file.txt)的形式,实现将文件上传至当前Bucket或Bucket下的指定目录。
50
- let objectKey = pathGenerate(data.name);
51
-
52
- let res = ossClient.multipartUpload(objectKey, data, {
53
- progress: function (p, checkpoint) {
54
- console.debug('progress callback', p, checkpoint);
55
- // 断点记录点。浏览器重启后无法直接继续上传,您需要手动触发上传操作。
56
- if (callback && callback instanceof Function) {
57
- callback(p, checkpoint,data,extCallback);
58
- }
59
- }
60
- })
61
- return res;
62
- }
63
-
64
- function ossFileUrl(ossConfig, path, cname) {
65
- if (cname == null) {
66
- return 'https://' + ossConfig.bucket + '.' + ossConfig.region + '.aliyuncs.com/' + path;
67
- } else {
68
- return cname + '/' + path;
69
- }
70
- }
71
-
72
- export {upload, multipartUpload, ossFileUrl}
1
+ const OSS = require('ali-oss');
2
+
3
+ let IDX = 256, HEX = [], SIZE = 256, BUFFER;
4
+ while (IDX--) HEX[IDX] = (IDX + 256).toString(16).substring(1);
5
+ let mainId = sessionStorage.getItem('_mainId') ? sessionStorage.getItem('_mainId') : "";
6
+ function uid(len) {
7
+ let i = 0, tmp = (len || 11);
8
+ if (!BUFFER || ((IDX + tmp) > SIZE * 2)) {
9
+ for (BUFFER = '', IDX = 0; i < SIZE; i++) {
10
+ BUFFER += HEX[Math.random() * 256 | 0];
11
+ }
12
+ }
13
+
14
+ return BUFFER.substring(IDX, IDX++ + tmp);
15
+ }
16
+
17
+ function dataFormat(fmt, date = new Date()) {
18
+ const o = {
19
+ "M+": date.getMonth() + 1, //月份
20
+ "d+": date.getDate(), //日
21
+ "h+": date.getHours(), //小时
22
+ "m+": date.getMinutes(), //分
23
+ "s+": date.getSeconds(), //秒
24
+ "q+": Math.floor((date.getMonth() + 3) / 3), //季度
25
+ "S": date.getMilliseconds() //毫秒
26
+ };
27
+ if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
28
+ for (const k in o)
29
+ if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
30
+ return fmt;
31
+ }
32
+
33
+ function pathGenerate(filename) {
34
+ return "front-oss/" + mainId + '/' + dataFormat("yyyy/MM/dd/hh/mm/") + uid(32) + "/" + filename;
35
+ }
36
+
37
+
38
+ function upload(ossConfig, data) {
39
+ let ossClient = new OSS(ossConfig);
40
+ // object-key可以自定义为文件名(例如file.txt)或目录(例如abc/test/file.txt)的形式,实现将文件上传至当前Bucket或Bucket下的指定目录。
41
+ let objectKey = pathGenerate(data.name);
42
+ let result = ossClient.put(objectKey, data);
43
+ console.debug(result);
44
+ return result;
45
+ }
46
+
47
+ function multipartUpload(ossConfig, data, callback,extCallback) {
48
+ let ossClient = new OSS(ossConfig);
49
+ // object-key可以自定义为文件名(例如file.txt)或目录(例如abc/test/file.txt)的形式,实现将文件上传至当前Bucket或Bucket下的指定目录。
50
+ let objectKey = pathGenerate(data.name);
51
+
52
+ let res = ossClient.multipartUpload(objectKey, data, {
53
+ progress: function (p, checkpoint) {
54
+ console.debug('progress callback', p, checkpoint);
55
+ // 断点记录点。浏览器重启后无法直接继续上传,您需要手动触发上传操作。
56
+ if (callback && callback instanceof Function) {
57
+ callback(p, checkpoint,data,extCallback);
58
+ }
59
+ }
60
+ })
61
+ return res;
62
+ }
63
+
64
+ function ossFileUrl(ossConfig, path, cname) {
65
+ if (cname == null) {
66
+ return 'https://' + ossConfig.bucket + '.' + ossConfig.region + '.aliyuncs.com/' + path;
67
+ } else {
68
+ return cname + '/' + path;
69
+ }
70
+ }
71
+
72
+ export {upload, multipartUpload, ossFileUrl}