design.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /**
  2. * [图片导航的图片]·组件
  3. */
  4. var graphicNavListHtml = '<div style="display: none;"></div>';
  5. Vue.component("graphic-nav-list", {
  6. template: graphicNavListHtml,
  7. data: function () {
  8. return {
  9. data: this.$parent.data,
  10. list: this.$parent.data.list,
  11. modeList: [
  12. {
  13. name: "图文导航",
  14. value: "graphic",
  15. src: "icontuwendaohang3"
  16. },
  17. {
  18. name: "图片导航",
  19. value: "img",
  20. src: "icontudaohang"
  21. },
  22. {
  23. name: "文字导航",
  24. value: "text",
  25. src: "iconwendaohang"
  26. }
  27. ],
  28. showStyleList: [
  29. {
  30. name: "固定显示",
  31. value: "fixed",
  32. src: "icongudingzhanshi"
  33. },
  34. {
  35. name: "单行滑动",
  36. value: "singleSlide",
  37. src: "icondanhanghuadong"
  38. },
  39. {
  40. name: "分页滑动",
  41. value: "pageSlide",
  42. src: "iconfenyehuadong"
  43. }
  44. ],
  45. ornamentList: [
  46. {
  47. type: 'default',
  48. text: '默认',
  49. },
  50. {
  51. type: 'shadow',
  52. text: '投影',
  53. },
  54. {
  55. type: 'stroke',
  56. text: '描边',
  57. },
  58. ],
  59. carouselList: [
  60. {
  61. name: "圆点",
  62. value: "circle",
  63. src: "iconshenglvehao"
  64. },
  65. {
  66. name: "直线",
  67. value: "straightLine",
  68. src: "iconshixian"
  69. },
  70. {
  71. name: "隐藏",
  72. value: "hide",
  73. src: "iconyincang"
  74. }
  75. ],
  76. rowCountList: [
  77. {
  78. name: "3个",
  79. value: 3,
  80. src: "iconyihangsange"
  81. },
  82. {
  83. name: "4个",
  84. value: 4,
  85. src: "iconyihangsige"
  86. },
  87. {
  88. name: "5个",
  89. value: 5,
  90. src: "iconyihang5ge"
  91. }
  92. ],
  93. pageCountList: [
  94. {
  95. name: "1行",
  96. value: 1,
  97. src: "iconfuzhushuxian"
  98. },
  99. {
  100. name: "2行",
  101. value: 2,
  102. src: "iconyihangliangge"
  103. }
  104. ],
  105. thicknessList: [
  106. {name: "加粗", src: "iconbold", value: "bold"},
  107. {name: "常规", src: "iconbold-copy", value: "normal"}
  108. ]
  109. };
  110. },
  111. created: function () {
  112. if (!this.$parent.data.verify) this.$parent.data.verify = [];
  113. this.$parent.data.verify.push(this.verify);//加载验证方法
  114. this.$parent.data.ignore = ['textColor', 'elementBgColor', 'elementAngle'];//加载忽略内容 -- 其他设置中的属性设置
  115. this.$parent.data.ignoreLoad = true; // 等待忽略数组赋值后加载
  116. // 组件所需的临时数据
  117. this.$parent.data.tempData = {
  118. ...this.$parent.data.tempData,
  119. modeList: this.modeList,
  120. showStyleList: this.showStyleList,
  121. ornamentList: this.ornamentList,
  122. carouselList: this.carouselList,
  123. rowCountList: this.rowCountList,
  124. pageCountList: this.pageCountList,
  125. thicknessList:this.thicknessList,
  126. carouselIndex: 0,
  127. methods: {
  128. addNav: this.addNav
  129. }
  130. };
  131. this.list.forEach(function (e, i) {
  132. if(!e.id ) e.id = ns.gen_non_duplicate(6);
  133. });
  134. this.$parent.data.list = this.list;
  135. var moveBeforeIndex = 0;
  136. var _this = this;
  137. setTimeout(function () {
  138. var componentIndex = _this.data.index;
  139. $('[data-index="' + componentIndex + '"] .navigation-set-list').DDSort({
  140. target: 'li',
  141. floatStyle: {
  142. 'border': '1px solid #ccc',
  143. 'background-color': '#fff'
  144. },
  145. //设置可拖拽区域
  146. draggableArea: "icontuodong",
  147. down: function (index) {
  148. moveBeforeIndex = index;
  149. },
  150. up: function () {
  151. var index = $(this).index();
  152. var temp = _this.list[moveBeforeIndex];
  153. _this.list.splice(moveBeforeIndex, 1);
  154. _this.list.splice(index, 0, temp);
  155. _this.$parent.data.list = _this.list;
  156. }
  157. });
  158. })
  159. },
  160. watch: {
  161. "data.pageCount"() {
  162. if (this.data.showStyle == 'pageSlide')
  163. this.data.tempData.carouselIndex = 0
  164. },
  165. "data.rowCount"() {
  166. if (this.data.showStyle == 'pageSlide')
  167. this.data.tempData.carouselIndex = 0
  168. }
  169. },
  170. methods: {
  171. addNav() {
  172. this.list.push({
  173. "title": "",
  174. "icon": "",
  175. "imageUrl": "",
  176. "iconType": "img",
  177. "style": {
  178. "fontSize": "60",
  179. "iconBgColor": [],
  180. "iconBgColorDeg": 0,
  181. "iconBgImg": "",
  182. "bgRadius": 0,
  183. "iconColor": [
  184. "#000000"
  185. ],
  186. "iconColorDeg": 0
  187. },
  188. "link": {
  189. "name": ""
  190. },
  191. "label": {
  192. "control": false,
  193. "text": "热门",
  194. "textColor": "#FFFFFF",
  195. "bgColorStart": "#F83287",
  196. "bgColorEnd": "#FE3423"
  197. },
  198. id: ns.gen_non_duplicate(6)
  199. });
  200. },
  201. verify: function (index) {
  202. var res = {code: true, message: ""};
  203. $(".draggable-element[data-index='" + index + "'] .graphic-navigation .graphic-nav-list .navigation-set-list>li").each(function (i) {
  204. if (vue.data[index].mode === "img") {
  205. $(this).find("input[name='title']").removeAttr("style");//清空输入框的样式
  206. //检测是否有未上传的图片
  207. if (vue.data[index].list[i].imageUrl === "") {
  208. res.code = false;
  209. res.message = "请选择一张图片";
  210. $(this).find(".error-msg").text("请选择一张图片").show();
  211. return res;
  212. } else {
  213. $(this).find(".error-msg").text("").hide();
  214. }
  215. } else {
  216. if (vue.data[index].list[i].title === "") {
  217. res.code = false;
  218. res.message = "请输入标题";
  219. $(this).find("input[name='title']").attr("style", "border-color:red !important;").focus();
  220. $(this).find(".error-msg").text("请输入标题").show();
  221. return res;
  222. } else {
  223. $(this).find("input[name='title']").removeAttr("style");
  224. $(this).find(".error-msg").text("").hide();
  225. }
  226. }
  227. });
  228. return res;
  229. }
  230. }
  231. });
  232. var uploadImgHtml = '<div class="img-icon-box">';
  233. uploadImgHtml += '<img-icon-upload :data="{data:myData.data}"></img-icon-upload>';
  234. uploadImgHtml += '<div class="action-box">';
  235. uploadImgHtml += '<div class="action" v-if="myData.data.iconType == \'icon\'" title="风格" @click="iconStyle($event)"><i class="iconfont iconpifu"></i></div>';
  236. uploadImgHtml += '<div class="action" v-if="myData.data.iconType == \'icon\'" title="背景" @click="selectColor(\'graphic-nav-color-\' +id)" :id="\'graphic-nav-color-\' +id"><i class="iconfont iconyanse"></i></div>';
  237. uploadImgHtml += '<div class="action" title="标签" @click="selectLabel()"><i class="iconfont iconbiaoqian1"></i></div>';
  238. uploadImgHtml += '</div>';
  239. uploadImgHtml += '</div>';
  240. Vue.component("image-upload", {
  241. template: uploadImgHtml,
  242. props: {
  243. data: {
  244. type: Object,
  245. default: function () {
  246. return {
  247. data: {},
  248. field: "",
  249. callback: null
  250. };
  251. }
  252. }
  253. },
  254. data: function () {
  255. return {
  256. myData: this.data,
  257. list: [],
  258. parent: this.$parent.data,
  259. id: ns.gen_non_duplicate(10),
  260. colorPicker:{}
  261. };
  262. },
  263. created: function () {
  264. if (this.myData.field === undefined) this.myData.field = "imageUrl";
  265. this.id = ns.gen_non_duplicate(10);
  266. },
  267. methods: {
  268. // 选择图标风格
  269. iconStyle(event) {
  270. var self = this;
  271. selectIconStyle({
  272. elem: event.currentTarget,
  273. icon: self.myData.data.icon,
  274. callback: function (data) {
  275. if (data) {
  276. self.myData.data.style = data;
  277. } else {
  278. iconStyleSet({
  279. style: JSON.stringify(self.myData.data.style),
  280. query: {
  281. icon: self.myData.data.icon
  282. }
  283. }, function (style) {
  284. self.myData.data.style = style;
  285. })
  286. }
  287. }
  288. })
  289. },
  290. /**
  291. * 渲染颜色组件
  292. * @param id
  293. * @param color
  294. * @param callback
  295. */
  296. colorRender(id, color, callback) {
  297. var self = this;
  298. if (this.colorPicker[id]) return;
  299. setTimeout(function () {
  300. self.colorPicker[id] = Colorpicker.create({
  301. el: id,
  302. color: color,
  303. change: function (elem, hex) {
  304. callback(elem, hex)
  305. }
  306. });
  307. $('#' + id).click();
  308. }, 10)
  309. },
  310. selectColor(id) {
  311. let self = this;
  312. this.colorRender(id, '', function (elem, color) {
  313. if (self.myData.data.style['iconBgImg'] || self.myData.data.style['iconBgColor'].length) {
  314. self.myData.data.style['iconBgColor'] = [color];
  315. } else {
  316. self.myData.data.style['iconColor'] = [color];
  317. }
  318. self.$forceUpdate();
  319. })
  320. },
  321. /**
  322. * 标签设置
  323. * @param data
  324. * @param callback
  325. */
  326. labelStyle(data, callback) {
  327. layer.open({
  328. title: "标签设置",
  329. type: 2,
  330. area: ['800px', '420px'],
  331. fixed: false, //不固定
  332. btn: ['保存', '取消'],
  333. content: ns.url("shop/diy/selectlabel", data ? data : {}),
  334. yes: function (index, layero) {
  335. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  336. iframeWin.getData(function (obj) {
  337. if (typeof callback == "string") {
  338. try {
  339. eval(callback + '(obj)');
  340. layer.close(index);
  341. } catch (e) {
  342. console.error('回调函数' + callback + '未定义');
  343. }
  344. } else if (typeof callback == "function") {
  345. callback(obj);
  346. layer.close(index);
  347. }
  348. });
  349. }
  350. });
  351. },
  352. selectLabel() {
  353. let self = this;
  354. this.labelStyle(self.myData.data.label, function (data) {
  355. self.myData.data.label = data;
  356. self.$forceUpdate();
  357. })
  358. }
  359. }
  360. });