weappNoticeCtrl.js
1.38 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
(function(angular) {
function weappNoticeCtrl($scope,wechatauthService,$q,toaster) {
$scope.model={
notice:'',
submitted:false,
submit
}
function submit(invalid){
$scope.model.submitted=true
if(invalid) return
__request('noticePush',$.param({notice:$scope.model.notice})).then(function(result){
result &&
toaster.pop({
type: 'success',
body: '发布成功',
timeout: 3000
});
})
}
/**
统一处理错误信息
*/
function getNotice(){
__request('noticeGet',{}).then(function(result){
if(result){
$scope.model.notice = result.notice
}
})
}
/**
统一处理错误信息
*/
function alerter(message,type){
swal({
type: type|| 'error',
title: '',
text: message||'',
showConfirmButton:false,
timer: 1500
},function(){
swal.close();
});
}
//统一处理接口请求
function __request(action,params){
// return new Promise(resolve=>{
var __def = $q.defer()
wechatauthService[action](params,function(result){
if(result.returnCode == '0'){
__def.resolve(result.data)
}else{
alerter(result.message)
__def.resolve(false)
}
})
return __def.promise
// })
}
//页面初始化
;(function init(){
getNotice()
})()
}
angular.module('wechatauth')
.controller('weappNoticeCtrl', weappNoticeCtrl);
})(angular);