operations.officialAccounts.Edit.js
2.54 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
webpackJsonp([115],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {
var $ = __webpack_require__(1), common = __webpack_require__(2);
var e = new common.edit('#editor-group', {bucket: "yhb-img01"});
e.on("render", function() {
$("#templateKey").select2({ minimumResultsForSearch: Infinity });
});
// 验证图片
e.on("validate", function() {
var img1 = $("#wechat1_img").attr("value");
if (img1.length == 0) {
return "请设置图片1";
}
var img2 = $("#wechat2_img").attr("value");
if (img2.length == 0) {
return "请设置图片2";
}
});
e.init();
// submit
$('#add-btn').click(function(option) {
e.submit($('#add-form').attr('action'), function(option) {
var data = buildToObjects(option.data);
addSuffix(data);
option.data.contentData = JSON.stringify(data);
option.beforeSend = function() {
$('#add-btn').addClass('disabled');
};
option.success = function(res) {
if (res.code == "200") {
e.$tip('提交成功', function() {
location.href = "/resources/officialAccounts/index";
}, 'growl-success');
} else {
$('#add-btn').removeClass('disabled');
e.$tip(res.message);
}
return false;
}
option.error = function(res) {
e.$tip("提交失败");
};
});
});
/**
* [
{
"wechat_name":"YOHOFamiliy",
"wechat_id":"yoho_familiy",
"src":""
},
{
"wechat_name":"YOHOFamiliy",
"wechat_id":"yoho_familiy",
"src":""
}
] */
function buildToObjects(data) {
var wechats = [];
wechats.push(Wechat(data.wechat_id1, data.wechat_name1, data.wechat1_img));
wechats.push(Wechat(data.wechat_id2, data.wechat_name2, data.wechat2_img));
return wechats;
}
function Wechat(id, name, src) {
return {
"wechat_id": id,
"wechat_name": name,
"src": src
};
}
var addSuffix = function (contentData) {
if (typeof contentData == "object") {
for (var i in contentData) {
if (i == "src" && contentData[i].indexOf("?") == -1) {
contentData[i] = contentData[i] + "?imageView2/{mode}/w/{width}/h/{height}";
} else {
addSuffix(contentData[i]);
}
}
}
return contentData;
};
/***/ }
]);