design.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /**
  2. * [图片导航的图片]·组件
  3. */
  4. var quickNavListHtml = '<div style="display: none;"></div>';
  5. Vue.component("quick-nav-list", {
  6. template: quickNavListHtml,
  7. data: function () {
  8. return {
  9. data: this.$parent.data,
  10. list: this.$parent.data.list,
  11. ornamentList: [
  12. {
  13. type: 'default',
  14. text: '默认',
  15. },
  16. {
  17. type: 'shadow',
  18. text: '投影',
  19. },
  20. {
  21. type: 'stroke',
  22. text: '描边',
  23. },
  24. ],
  25. };
  26. },
  27. created: function () {
  28. if (!this.$parent.data.verify) this.$parent.data.verify = [];
  29. this.$parent.data.verify.push(this.verify);//加载验证方法
  30. this.$parent.data.ignore = ['textColor', 'elementBgColor', 'elementAngle'];//加载忽略内容 -- 其他设置中的属性设置
  31. this.$parent.data.ignoreLoad = true; // 等待忽略数组赋值后加载
  32. // 组件所需的临时数据
  33. this.$parent.data.tempData = {
  34. ...this.$parent.data.tempData,
  35. ornamentList: this.ornamentList,
  36. methods: {
  37. addNav: this.addNav
  38. }
  39. };
  40. this.list.forEach(function (e, i) {
  41. if(!e.id) e.id = ns.gen_non_duplicate(6);
  42. });
  43. this.$parent.data.list = this.list;
  44. var moveBeforeIndex = 0;
  45. var _this = this;
  46. setTimeout(function () {
  47. var componentIndex = _this.data.index;
  48. $('[data-index="' + componentIndex + '"] .navigation-set-list').DDSort({
  49. target: 'li',
  50. floatStyle: {
  51. 'border': '1px solid #ccc',
  52. 'background-color': '#fff'
  53. },
  54. //设置可拖拽区域
  55. draggableArea: "icontuodong",
  56. down: function (index) {
  57. moveBeforeIndex = index;
  58. },
  59. up: function () {
  60. var index = $(this).index();
  61. var temp = _this.list[moveBeforeIndex];
  62. _this.list.splice(moveBeforeIndex, 1);
  63. _this.list.splice(index, 0, temp);
  64. _this.$parent.data.list = _this.list;
  65. }
  66. });
  67. })
  68. },
  69. methods: {
  70. addNav() {
  71. this.list.push({
  72. "title": "",
  73. "icon": "",
  74. "iconType": "img",
  75. "imageUrl": "",
  76. "style": {
  77. "fontSize": "60",
  78. "iconBgColor": [],
  79. "iconBgColorDeg": 0,
  80. "iconBgImg": "",
  81. "bgRadius": 0,
  82. "iconColor": [
  83. "#000000"
  84. ],
  85. "iconColorDeg": 0
  86. },
  87. "link": {
  88. "name": ""
  89. },
  90. "bgColorStart": "",
  91. "bgColorEnd": "",
  92. "textColor": "#303133",
  93. id: ns.gen_non_duplicate(6)
  94. });
  95. },
  96. verify: function (index) {
  97. var res = {code: true, message: ""};
  98. $(".draggable-element[data-index='" + index + "'] .quick-navigation .quick-nav-list .navigation-set-list>li").each(function (i) {
  99. if (vue.data[index].list[i].title === "") {
  100. res.code = false;
  101. res.message = "请输入标题";
  102. $(this).find("input[name='title']").attr("style", "border-color:red !important;").focus();
  103. return res;
  104. } else {
  105. $(this).find("input[name='title']").removeAttr("style");
  106. }
  107. });
  108. return res;
  109. }
  110. }
  111. });
  112. var quickUploadImgHtml = '<div class="img-icon-box">';
  113. quickUploadImgHtml += '<img-icon-upload :data="{data:myData.data}"></img-icon-upload>';
  114. quickUploadImgHtml += '<div class="action-box">';
  115. quickUploadImgHtml += '<div class="action" v-if="myData.data.iconType == \'icon\'" title="风格" @click="iconStyle($event)"><i class="iconfont iconpifu"></i></div>';
  116. quickUploadImgHtml += '<div class="action" v-if="myData.data.iconType == \'icon\'" title="背景" @click="selectColor(\'quick-nav-color-\' +id)" :id="\'quick-nav-color-\' +id"><i class="iconfont iconyanse"></i></div>';
  117. quickUploadImgHtml += '</div>';
  118. quickUploadImgHtml += '</div>';
  119. Vue.component("quick-image-upload", {
  120. template: quickUploadImgHtml,
  121. props: {
  122. data: {
  123. type: Object,
  124. default: function () {
  125. return {
  126. data: {},
  127. field: "",
  128. callback: null
  129. };
  130. }
  131. }
  132. },
  133. data: function () {
  134. return {
  135. myData: this.data,
  136. list: [],
  137. parent: this.$parent.data,
  138. id: '',
  139. colorPicker:{}
  140. };
  141. },
  142. created: function () {
  143. this.id = ns.gen_non_duplicate(10);
  144. },
  145. methods: {
  146. // 选择图标风格
  147. iconStyle(event) {
  148. var self = this;
  149. selectIconStyle({
  150. elem: event.currentTarget,
  151. icon: self.myData.data.icon,
  152. callback: function (data) {
  153. if (data) {
  154. self.myData.data.style = data;
  155. } else {
  156. iconStyleSet({
  157. style: JSON.stringify(self.myData.data.style),
  158. query: {
  159. icon: self.myData.data.icon
  160. }
  161. }, function (style) {
  162. self.myData.data.style = style;
  163. })
  164. }
  165. }
  166. })
  167. },
  168. /**
  169. * 渲染颜色组件
  170. * @param id
  171. * @param color
  172. * @param callback
  173. */
  174. colorRender(id, color, callback) {
  175. var self = this;
  176. if (this.colorPicker[id]) return;
  177. setTimeout(function () {
  178. self.colorPicker[id] = Colorpicker.create({
  179. el: id,
  180. color: color,
  181. change: function (elem, hex) {
  182. callback(elem, hex)
  183. }
  184. });
  185. $('#' + id).click();
  186. }, 10)
  187. },
  188. selectColor(id) {
  189. let self = this;
  190. this.colorRender(id, '', function (elem, color) {
  191. if (self.myData.data.style['iconBgImg'] || self.myData.data.style['iconBgColor'].length) {
  192. self.myData.data.style['iconBgColor'] = [color];
  193. } else {
  194. self.myData.data.style['iconColor'] = [color];
  195. }
  196. self.$forceUpdate();
  197. })
  198. },
  199. }
  200. });