design.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /**
  2. * 公告·组件
  3. */
  4. var noticeConHtml = '<div style="display:none;"></div>';
  5. Vue.component("notice-sources", {
  6. template: noticeConHtml,
  7. data: function () {
  8. return {
  9. data: this.$parent.data,
  10. list: this.$parent.data.list,
  11. noticeSources: {
  12. initial: {
  13. text: "默认",
  14. icon: "iconmofang"
  15. },
  16. diy: {
  17. text: "手动选择",
  18. icon: "iconshoudongxuanze"
  19. },
  20. },
  21. iconList: {
  22. initial: {
  23. text: "系统图标",
  24. type: 'img',
  25. src: "iconshangpinfenlei",
  26. icon: [(noticeRelativePath + "/img/notice_01.png"), (noticeRelativePath + "/img/notice_02.png"), (noticeRelativePath + "/img/notice_03.png")]
  27. },
  28. diy: {
  29. type: 'icon',
  30. text: "自定义",
  31. src: "iconshoudongxuanze",
  32. }
  33. },
  34. thicknessList: [
  35. {name: "加粗", src: "iconbold", value: "bold"},
  36. {name: "常规", src: "iconbold-copy", value: "normal"}
  37. ]
  38. }
  39. },
  40. created: function () {
  41. if (!this.$parent.data.verify) this.$parent.data.verify = [];
  42. this.$parent.data.verify.push(this.verify);//加载验证方法
  43. // 赋值初始化图片
  44. if (!this.data.imageUrl) this.data.imageUrl = this.iconList.initial.icon[0];
  45. this.$parent.data.ignore = ['elementBgColor', 'elementAngle'];//加载忽略内容 -- 其他设置中的属性设置
  46. this.$parent.data.ignoreLoad = true; // 等待忽略数组赋值后加载
  47. // 组件所需的临时数据
  48. this.$parent.data.tempData = {
  49. noticeSources: this.noticeSources,
  50. iconList: this.iconList,
  51. thicknessList: this.thicknessList,
  52. methods: {
  53. selectNotice: this.selectNotice,
  54. addNotice: this.addNotice,
  55. iconStyle: this.iconStyle
  56. }
  57. };
  58. this.list.forEach(function (e, i) {
  59. if(!e.id ) e.id = ns.gen_non_duplicate(6);
  60. });
  61. this.$parent.data.list = this.list;
  62. var moveBeforeIndex = 0;
  63. var _this = this;
  64. setTimeout(function () {
  65. var componentIndex = _this.data.index;
  66. $('[data-index="' + componentIndex + '"] .notice-config ul').DDSort({
  67. target: 'li',
  68. floatStyle: {
  69. 'border': '1px solid #ccc',
  70. 'background-color': '#fff'
  71. },
  72. //设置可拖拽区域
  73. draggableArea: "icontuodong",
  74. down: function (index) {
  75. moveBeforeIndex = index;
  76. },
  77. up: function () {
  78. var index = $(this).index();
  79. var temp = _this.list[moveBeforeIndex];
  80. _this.list.splice(moveBeforeIndex, 1);
  81. _this.list.splice(index, 0, temp);
  82. _this.$parent.data.list = _this.list;
  83. }
  84. });
  85. })
  86. },
  87. mounted() {
  88. this.fetchIconColor();
  89. },
  90. watch: {
  91. '$parent.data.sources':function (oVal,nVal) {
  92. if(oVal == 'initial') return;
  93. var moveBeforeIndex = 0;
  94. var _this = this;
  95. setTimeout(function () {
  96. var componentIndex = _this.data.index;
  97. $('[data-index="' + componentIndex + '"] .notice-config ul').DDSort({
  98. target: 'li',
  99. floatStyle: {
  100. 'border': '1px solid #ccc',
  101. 'background-color': '#fff'
  102. },
  103. //设置可拖拽区域
  104. draggableArea: "icontuodong",
  105. down: function (index) {
  106. moveBeforeIndex = index;
  107. },
  108. up: function () {
  109. var index = $(this).index();
  110. var temp = _this.list[moveBeforeIndex];
  111. _this.list.splice(moveBeforeIndex, 1);
  112. _this.list.splice(index, 0, temp);
  113. _this.$parent.data.list = _this.list;
  114. }
  115. });
  116. })
  117. }
  118. },
  119. methods: {
  120. verify: function (index) {
  121. var res = {code: true, message: ""};
  122. if (vue.data[index].list.length > 0) {
  123. for (var i = 0; i < vue.data[index].list.length; i++) {
  124. if (vue.data[index].list[i].title === "") {
  125. res.code = false;
  126. res.message = "公告内容不能为空";
  127. break;
  128. }
  129. }
  130. } else {
  131. res.code = false;
  132. res.message = "请添加一条公告";
  133. }
  134. return res;
  135. },
  136. selectNotice: function () {
  137. var self = this;
  138. self.noticeSelect(function (res) {
  139. self.$parent.data.noticeIds = [];
  140. self.$parent.data.list = [];
  141. for (var i = 0; i < res.length; i++) {
  142. self.$parent.data.noticeIds.push(res[i].id);
  143. self.$parent.data.list[i] = {
  144. title: res[i].title,
  145. link: {},
  146. id: res[i].id
  147. };
  148. }
  149. self.list = self.$parent.data.list;
  150. }, self.$parent.data.noticeIds);
  151. },
  152. addNotice:function () {
  153. this.list.push({
  154. id: ns.gen_non_duplicate(6),
  155. title: '公告',
  156. link: {name: ''}
  157. })
  158. },
  159. /**
  160. * 选择图标风格
  161. * @param event
  162. */
  163. iconStyle(event) {
  164. var self = this;
  165. selectIconStyle({
  166. elem: event.currentTarget,
  167. icon: self.data.icon,
  168. callback: function (data) {
  169. if (data) {
  170. self.data.style = data;
  171. } else {
  172. iconStyleSet({
  173. style: JSON.stringify(self.data.style),
  174. query: {
  175. icon: self.data.icon
  176. }
  177. }, function (style) {
  178. self.data.style = style;
  179. })
  180. }
  181. }
  182. })
  183. },
  184. /**
  185. * 渲染颜色组件
  186. * @param id
  187. * @param color
  188. * @param callback
  189. */
  190. colorRender(id, color, callback) {
  191. setTimeout(function () {
  192. Colorpicker.create({
  193. el: id,
  194. color: color,
  195. change: function (elem, hex) {
  196. callback(elem, hex)
  197. }
  198. });
  199. })
  200. },
  201. /**
  202. * 渲染图标颜色选择器
  203. */
  204. fetchIconColor() {
  205. var self = this;
  206. self.colorRender('notice-color-' + self.data.index, '', function (elem, color) {
  207. if (self.data.style.iconBgColor.length || self.data.style.iconBgImg) {
  208. self.data.style.iconBgColor = [color];
  209. } else {
  210. self.data.style.iconColor = [color];
  211. }
  212. self.$forceUpdate();
  213. });
  214. },
  215. noticeSelect: function (callback, selectId) {
  216. var self = this;
  217. layui.use(['layer'], function () {
  218. var url = ns.url("shop/notice/noticeselect", {select_id: selectId.toString()});
  219. //iframe层-父子操作
  220. layer.open({
  221. title: "公告选择",
  222. type: 2,
  223. area: ['1000px', '600px'],
  224. fixed: false, //不固定
  225. btn: ['保存', '返回'],
  226. content: url,
  227. yes: function (index, layero) {
  228. var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
  229. iframeWin.selectNotice(function (obj) {
  230. if (typeof callback == "string") {
  231. try {
  232. eval(callback + '(obj)');
  233. layer.close(index);
  234. } catch (e) {
  235. console.error('回调函数' + callback + '未定义');
  236. }
  237. } else if (typeof callback == "function") {
  238. callback(obj);
  239. layer.close(index);
  240. }
  241. });
  242. }
  243. });
  244. });
  245. },
  246. }
  247. });