resourceContentManage.js
8.72 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
/**
* Created by ty on 2016/3/31.
* 资源内容管理
*/
var $ = require('jquery'),
common = require('../common/common'),
util = require('../common/util');
var param = location.href.substring(location.href.lastIndexOf("/") + 1);
var resources = {};
var btns = [
{name:"text",text:"文本"},
{name:"singleImage",text:"一张图"},
{name:"smallPic",text:"添加小图"},
{name:"focus",text:"焦点图"},
{name:"goods",text:"添加商品"},
{name:"goodsGroup",text:"添加商品组"},
{name:"appIconList",text:"图标入口"},
{name:"recommendContentOne",text:"推荐(1T-1L-4R)"},
{name:"recommendContentTwo",text:"推荐(1T-6F)"},
{name:"singleNameImage",text:"标题广告"},
{name:"recommendContentThree",text:"推荐(1T-12F)"},
{name:"trendsetterCollocation",text:"潮人搭配"},
{name:"trendgoodsTopic",text:"潮品话题"},
{name:"customBrands",text:"推荐品牌"},
{name:"customBrands",text:"自定义品牌"},
{name:"link",text:"一个链接"},
{name:"promotion",text:"添加促销"},
{name:"carouselBanner",text:"轮播banner"},
{name:"kidsBrands",text:"kids品牌"},
{name:"",text:"推荐(L1-RT1-RF2)"},
{name:"",text:"添加楼层"},
{name:"recommendContentFive",text:"推荐(标题 + 12张图)"},
{name:"textNav",text:"文本导航"},
{name:"imageList",text:"图片列表"},
{name:"",text:"标题标签"},
{name:"",text:"编辑推荐"},
{name:"hotCategory",text:"热门品类"},
{name:"debrisSlider",text:"有序焦点"},
{name:"newUserFloor",text:"新人专享"},
{name:"singleNameImage",text:"图片广告"},
{name:"paramsGroup",text:"自定义参数"},
{name:"",text:"自定义参数的图片"},
{name:"announcement",text:"站内公告"}
];
var Bll = {
addView: function(item) {
switch (item.template_name) {
case "text":
Bll.addText(item.data?item.data.text:"");
break;
case "singleImage":
break;
case "smallPic":
break;
case "focus":
break;
case "goods":
break;
case "goodsGroup":
break;
case "appIconList":
break;
case "recommendContentOne":
break;
case "recommendContentTwo":
break;
case "singleNameImage":
break;
case "recommendContentThree":
break;
case "trendsetterCollocation":
break;
case "trendgoodsTopic":
break;
case "customBrands":
break;
case "link":
break;
case "promotion":
break;
case "carouselBanner":
break;
case "kidsBrands":
break;
case "recommendContentFive":
break;
case "textNav":
break;
case "imageList":
break;
case "hotCategory":
break;
case "debrisSlider":
break;
case "newUserFloor":
break;
case "paramsGroup":
break;
}
},
editTotal:function(item) {
},
addText:function(text) {
$("#add-content").append(function (index, html) {
var tempArr = [];
var index = $("#add-content").children().length;
tempArr.push('<li class="custom-group text" data-type="text" id="index_' + index + '">');
tempArr.push('<div class="con" id="index__'+ index +'">' + text + '</div>');
tempArr.push('<div class="actions-box"><div class="actions-wrap">');
tempArr.push('<span class="edit" data-value="文本" data-index="' + index + '">编辑</span>');
tempArr.push('<span class="del" data-id="" data-index="' + index + '">删除</span>');
tempArr.push('</div></div></li>');
return tempArr.join("");
});
},
editText:function(text) {
}
};
common.util.__ajax({
url: "/resource/content/resContentIndex",
data: {id: param}
},function(res) {
console.log(res.data);
resources = res.data;
$("#content-list").html(common.util.__template2($("#content-template").html(), res.data));
for(var i = 0; i < res.data.contentData.length; i++) {
var item = res.data.contentData[i];
var json = JSON.parse(item.contentData);
Bll.addView(json);
//console.log(json);
}
for(var i = 0; i < btns.length; i++) {
var button = btns[i];
$(".clearfix").append(function () {
var tempArr = [];
tempArr.push("<li><a href='javascript:void(0)' name='"+ button.name +"' class='add_btn' data-index='"+ i +"'>");
tempArr.push(button.text);
tempArr.push("</a></li>");
return tempArr.join("");
});
}
},true);
var buttons=[
{
title:"文本",
template:{
content:function() {
$("#add-content").append(function (index, html) {
var tempArr = [];
var index = $("#add-content").children().length;
tempArr.push('<li class="custom-group text" data-type="text" id="index_' + index + '">');
tempArr.push('<div class="con" id="index__'+ index +'"></div>');
tempArr.push('<div class="actions-box"><div class="actions-wrap">');
tempArr.push('<span class="edit" data-value="文本" data-index="' + index + '">编辑</span>');
tempArr.push('<span class="del" data-id="" data-index="' + index + '">删除</span>');
tempArr.push('</div></div></li>');
return tempArr.join("");
});
},
dialog:{
id:"#text-template",
title:"新增文本"
}
},
data:function(index) {
return {content: $("#index__" + index).html()};
},
button:{
add:function(index){
$("#index__" + index).html($("#myArea").val());
}
}
},
{
title:"一张图",
template:{
content:function() {
$("#add-content").append(function (index, html) {
var tempArr = [];
var index = $("#add-content").children().length;
tempArr.push('<li class="custom-group text" data-type="singleImage" id="index_' + index + '">');
tempArr.push('<div class="con" id="index__' + index + '"><img src="/js/source/plugins/addBigPic/bigPic.jpg" width="96%/"></div>');
tempArr.push('<div class="actions-box"><div class="actions-wrap">');
tempArr.push('<span class="edit" data-value="一张图" data-index="' + index + '">编辑</span>');
tempArr.push('<span class="del" data-id="" data-index="' + index + '">删除</span>');
tempArr.push('</div></div></li>');
return tempArr.join("");
});
},
dialog:{
id:"#singleImage-template",
title:"添加图片"
}
},
data:function(index) {
return {content: $("#index__" + index).find("img").val()};
},
button:{
add:function(index){
$("#index__" + index).html($("#myArea").val());
}
}
}
];
$(document).on("click",".add_btn",function(){//添加
//var title=$(this).html();
//var index = parseInt($(this).attr("data-index"));
////console.log(title);
//var btn=buttons.filter(function(item){
// return item.title==title;
//});
//btn[0].template.content();
Bll.addView({template_name:$(this).attr("name")});
});
$(document).on("click", ".edit", function() {//编辑
var title = $(this).attr("data-value");
var btn=buttons.filter(function(item){
return item.title==title;
});
var index = $(this).attr("data-index");
//console.log($("index_" + index));
//console.log($("#nidaye").html());
console.log(btn[0].data(index));
var e = new common.edit();
common.dialog.confirm(btn[0].template.dialog.title,
common.util.__template2($(btn[0].template.dialog.id).html(), btn[0].data(index)),
function() {
btn[0].button.add(index);
});
e.init();
});
$(document).on("click", ".del", function () {//删除
var index = $(this).attr("data-index");
$("#index_" + index).remove();
});
//for Button ->title
// [[each Button ]]
// <div class="btn">[[item.title]]</div>
// [[/each]]