miniProgramCtrl.js
14.7 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
;(function (angular) {
function miniProgramCtrl ($scope, DTOptionsBuilder, DTColumnBuilder, wechatauthService, $uibModal, $q, $state, ext) {
// 应用状态:0为已发布,1为待提交,2为提交失败,3为待审核,4为审核失败,5为审核撤回,6为待发布(审核成功),7为已回退
const statusMap = {
'': '全部',
'1': '待提交代码',
'2': '提交代码失败',
'3': '待提交审核',
'4': '审核中',
'5': '审核失败',
'6': '待发布',
'0': '已发布',
'7': '已回退'
}
$scope.binding = {
versions: [
{userVersion: '全部',templateId: ''}
],
objUpdateTime: null
}
const openDialogs = {
mpCommitCodes: {
path: 'mp-commit-codes',
controller: 'mpCommitCodes',
defaultData: 'versions',
callback: (row, data) => {
const { templateId, userDesc, userVersion } = data
__commitCodes({merchantIds: [row.merchantId],templateId, userDesc, userVersion})
}
},
mpCommitCodesBatch: {
path: 'mp-commit-codes',
controller: 'mpCommitCodes',
defaultData: 'versions',
callback: function (row, data) {
var arrStatus =['0','1','2','3','7'] //只有[已发布,待提交,待提交审核,提交失败,已回退]状态才能提交代码
const merchantIds = getCheckedMerchantIds(arrStatus)
if(!merchantIds.length) return
const { templateId, userDesc, userVersion } = data
__commitCodes({merchantIds,templateId, userDesc, userVersion})
}
},
mpQRCode: {
path: 'mp-qr-code',
controller: 'mpQRCode',
defaultData: null,
callback: () => {
}
},
mpAddMember: {
path: 'mp-add-member',
controller: 'mpAddMember',
defaultData: null,
callback: () => {
}
},
mpReasons: {
path: 'mp-reasons',
controller: 'mpReasons',
defaultData: null,
callback: function (row) {}
}
}
const confirmDialogs = {
opCommitCodesBatch: {
dialog: {title: '批量提交代码',content: '是否确认批量提交代码?'},
beforeDialog,
callback: function () {
doOpen('', '', openDialogs.mpCommitCodesBatch)
}
},
opCommitVerifyBatch: {
dialog: {title: '批量提交审核',content: ' 是否确认批量提交审核?'},
beforeDialog,
callback: function () {
var arrStatus =['3','5'] //只有[待提交审核,审核失败]状态才能提交审核
var merchantIds = getCheckedMerchantIds(arrStatus)
if(!merchantIds.length) return
__commitVerify(merchantIds)
}
},
opCommitReleaseBatch: {
dialog: {title: '批量提交发布',content: ' 是否确认批量提交发布?'},
beforeDialog,
callback: function () {
var arrStatus =['6'] //只有[待发布]状态才能发布
var merchantIds = getCheckedMerchantIds(arrStatus)
if(!merchantIds.length) return
__release(merchantIds)
}
},
opCommitVerify: {
dialog: {title: '提交审核',content: ' 是否确认提交审核?'},
callback: function (row) {
__commitVerify([row.merchantId])
}
},
opRebackVerify: {
dialog: {title: '撤回审核',content: ' 是否确认撤回审核?'},
callback: function (row) {
__rebackVerify([row.merchantId])
}
},
opRebackVersion: {
dialog: {title: '版本回退',content: ' 是否确认版本回退?'},
callback: function (row) {
__rebackVersion([row.merchantId])
}
},
opRelease: {
dialog: {title: '发布版本',content: ' 是否确认发布?'},
callback: function (row) {
__release([row.merchantId])
}
}
}
function filterMerchantId(arrStatus,merchantIds){
var _filter_merchant_ids =[]
var obj = null
for(var i = 0; i<merchantIds.length;i++){
obj = merchantIds[i]
if(arrStatus.indexOf(obj.appStatus+'')>=0){
_filter_merchant_ids.push(obj.merchantId)
}
}
return _filter_merchant_ids
}
function getCheckedMerchantIds (arrStatus) {
var _selectedItems = $scope.dtInstance.getSelectItems()
if(!_selectedItems.length) return []
return filterMerchantId(arrStatus,_selectedItems)
// return _selectedItems.map(function(item){
// return {'merchantId':item.merchantId,'appStatus':item.appStatus}
// })
}
function beforeDialog () {
// return new Promise(resolve=>{
var __def = $q.defer()
var _selectedItems = $scope.dtInstance.getSelectItems()
if (_selectedItems.length) {
__def.resolve(_selectedItems)
}else {
__def.resolve(null)
}
return __def.promise
// })
}
$scope.model = {
type: 'merchantName',
type_val: '',
appStatus: '',
currentVersion: '全部',
search,
searchTxt: '',
beginDate: '',
endDate: '',
multiChecked: false,
takeOptions: {
eventHandlers: {
'apply.daterangepicker': function (ev, picker) {
$scope.model.beginDate = `${picker.startDate.format('YYYY-MM-DD')} 00:00:00`
$scope.model.endDate = `${picker.endDate.format('YYYY-MM-DD')} 23:59:59`
},
'cancel.daterangepicker': function (ev, picker) {
$scope.model.beginDate = ''
$scope.model.endDate = ''
$scope.binding.objUpdateTime = {}
$scope.binding.objUpdateTime.startDate = null
$scope.binding.objUpdateTime.endDate = null
$scope.$apply()
}
}
},
// 提交代码
mpCommitCodes: (row) => doOpen('mpCommitCodes', row),
// 二维码体验
mpQRCode: (row) => doOpen('mpQRCode', row),
// 添加微信体验成员
mpAddMember: (row) => doOpen('mpAddMember', row),
// 查看原因
mpReasons: (row) => doOpen('mpReasons', row),
// 批量提交代码
opCommitCodesBatch: (row) => confirm('opCommitCodesBatch', row),
// 批量提交审核
opCommitVerifyBatch: (row) => confirm('opCommitVerifyBatch', row),
// 提交审核
opCommitVerify: (row) => confirm('opCommitVerify', row),
// 撤回审核
opRebackVerify: (row) => confirm('opRebackVerify', row),
// 版本回退
opRebackVersion: (row) => confirm('opRebackVersion', row),
// 发布
opRelease: (row) => confirm('opRelease', row),
// 批量发布
opCommitReleaseBatch: (row) => confirm('opCommitReleaseBatch', row),
statusMap}
/**
直接弹框打开一个操作
*/
function doOpen (key, row, openDialog) {
let {path, controller, defaultData, callback} = openDialog || openDialogs[key]
open(`biz/wechatauth/view/operation/${path}.html`, controller, {data: $scope.binding[defaultData],row,alerter,request: __request}, function (data) {
callback(row, data)
})
}
/**
需要确认的操作
*/
function confirm (key, row) {
const {dialog, callback, beforeDialog} = confirmDialogs[key]
if (beforeDialog) {
beforeDialog().then(result => {
const __dialog = result ? dialog : {title: '提示',content: '请选择',isNotShowOk: true}
open('biz/wechatauth/view/operation/confirm.html', 'confirm', __dialog, function (data) {
callback(row, data)
}, 'sm')
})
}else {
open('biz/wechatauth/view/operation/confirm.html', 'confirm', dialog, function (data) {
callback(row, data)
}, 'sm')
}
}
function search () {
var __params = getParams()
$scope.dtInstance.query(__params)
}
/**
接口请求 与业务无关 begin
*/
// 提交代码
function __commitCodes (params) {
__request('commitCodes', params).then(function () {
___success('提交代码成功!')
})
}
// 提交审核
function __commitVerify (params) {
__request('commitVerify', params).then(function () {
___success('提交审核成功!')
})
}
// 撤回审核
function __rebackVerify (params) {
__request('rebackVerify', params).then(function () {
___success('撤回审核成功!')
})
}
// 版本回退
function __rebackVersion (params) {
__request('rebackVersion', params).then(function () {
___success('版本回退成功!')
})
}
// 发布
function __release (params) {
__request('release', params).then(function () {
___success('发布成功!')
})
}
// 操作成功 并 刷新列表
function ___success (msg) {
alerter(msg, 'success')
search()
}
// 获取版本
function loadVersions () {
__request('templateList', {}).then(function (result) {
$scope.binding.versions = $scope.binding.versions.concat(result.data)
$scope.model.version = ''
})
}
// 统一处理请求
function __request (action, params) {
var __def = $q.defer()
// return new Promise((resolve,reject)=>{
wechatauthService[action](params, function (result) {
if (result.returnCode == '0') {
__def.resolve(result)
}else {
alerter(result.message)
__def.reject()
}
})
return __def.promise
// })
}
/**
接口请求 与业务无关 ======end======
*/
$scope.do = function (action, merchantId) {
$scope.model[action](merchantId)
}
const operations = {
'0': `<a class="btn btn-link" ng-click="do('mpCommitCodes',{0})">提交代码</a>`,
'1': `<a class="btn btn-link" ng-click="do('mpReasons',{0})">查看原因</a>`,
'2': `<a class="btn btn-link" ng-click="do('opCommitVerify',{0})">提交审核</a>`,
'3': `<a class="btn btn-link" ng-click="do('mpQRCode',{0})">体验二维码</a>`,
'4': `<a class="btn btn-link" ng-click="do('mpAddMember',{0})">体验成员</a>`,
'5': `<a class="btn btn-link" ng-click="do('opRebackVerify',{0})">撤回审核</a>`,
'6': `<a class="btn btn-link" ng-click="do('opRelease',{0})">发布</a>`,
'7': `<a class="btn btn-link" ng-click="do('opRebackVersion',{0})">版本回退</a>`
}
// 应用状态:0为已发布,1为待提交,2为提交失败,3为待审核,4为审核失败,5为审核撤回,6为待发布(审核成功),7为已回退
const opMap = {
'0': `${operations['0']}${operations['7']}`, // 已发布
'1': `${operations['0']}`, // 待提交代码
'2': `${operations['0']}${operations['1']}`, // 提交代码失败
'3': `${operations['2']}${operations['3']}${operations['4']}${operations['0']}`, // 待提交审核
'4': `${operations['5']}`, // 审核中
'5': `${operations['1']}${operations['2']}`, // 审核失败
'6': `${operations['6']}`, // 待发布(审核成功)
'7': `${operations['0']}` // 已回退
}
$scope.dtColumns = [
DTColumnBuilder.newColumn('merchantName').withOption('width', 140).withTitle('商户名称'),
DTColumnBuilder.newColumn('weappLogo').withOption('width', 140).withTitle('小程序图标')
.renderWith(data => `<img src="${data}" width="50px" height="50px">`),
DTColumnBuilder.newColumn('weappNickname').withOption('width', 200).withTitle('小程序名称'),
DTColumnBuilder.newColumn('appId').withOption('width', 200).withTitle('AppID'),
DTColumnBuilder.newColumn('appStatus').withOption('width', 200).withTitle('状态')
.renderWith(data => statusMap[data]),
DTColumnBuilder.newColumn('currentVersion').withOption('width', 200).withTitle('当前版本号'),
DTColumnBuilder.newColumn('currentVersionInfo').withOption('width', 200).withTitle('描述'),
DTColumnBuilder.newColumn('updatedDate').withOption('width', 200).withTitle('更新时间'),
DTColumnBuilder.newColumn(null).withTitle(() => '操作')
.withOption('width', 280)
.renderWith(data => `<div class="operation">${opMap[data.appStatus].FORMAT(JSON.stringify(data).replace(/\"/g,"'"))}</div>`)
]
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('id', 'id')
.withFixedColumns({
leftColumns: 0,
rightColumns: 1
})
.withOption('select', {
type: 'checkbox'
})
// .withDataProp('data.list')
.withButtons([{
text: '批量提交代码',
className: 'btn btn-primary',
action: function (e, dt, node, config) {
$scope.model.opCommitCodesBatch()
}
}, {
text: '批量提交审核',
className: 'btn btn-primary',
action: function (e, dt, node, config) {
$scope.model.opCommitVerifyBatch()
}
}, {
text: '批量提交发布',
className: 'btn btn-primary',
action: function (e, dt, node, config) {
$scope.model.opCommitReleaseBatch()
}
}])
// $scope.$watch('getCheckedMerchantIds()', function (ids) {
// $scope.model.multiChecked = ids && ids.length
// })
$scope.dtInstance = {
serverData: wechatauthService.loadList
}
function getParams () {
var obj = {}
obj[$scope.model.type] = $scope.model.searchTxt
var {appStatus, currentVersion, beginDate, endDate} = $scope.model
currentVersion = currentVersion === '全部' ? '' : currentVersion
var condition = angular.extend({}, obj, {appStatus,currentVersion,beginDate,endDate})
condition = removeEmptyParam(condition)
if ($.isEmptyObject(condition)) {
return {}
}
return {condition}
}
function removeEmptyParam (params) {
for (var key in params) {
!params[key] && delete params[key]
}
return params
}
function open (templateUrl, controller, defaultData, result, size) {
$uibModal.open({
templateUrl,
controller,
size: size || 'md',
resolve: {
data: () => {
return {defaultData}
}
}
}).result.then(result)
}
function alerter (message, type) {
swal({
type: type || 'error',
title: '',
text: message || '',
showConfirmButton: false,
timer: 1500
}, function () {
swal.close()
})
}
// function error(message){
// swal({
// type: 'error',
// title: '',
// text: message||'',
// showConfirmButton:false,
// timer: 1500
// },function(){
// swal.close()
// })
// }
;(function init () {
loadVersions()
})()
}
angular.module('wechatauth').controller('miniProgramCtrl', miniProgramCtrl)
})(angular)