style.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. // 图文导航·组件
  2. var graphicNavPreviewHtml = '<div v-bind:id="id" class="graphic-nav">';
  3. graphicNavPreviewHtml += '<div class="wrap" v-bind:style="{}">';
  4. graphicNavPreviewHtml += '<div v-for="(item, index) in list" v-if="index<data.showType*2" class="item" :style="{width: 333/data.showType + \'px\'}">';
  5. graphicNavPreviewHtml += '<a href="javascript:;">';
  6. graphicNavPreviewHtml += '<div v-show="data.selectedTemplate ==\'imageNavigation\'" style="width: 35px; height: 35px; line-height: 35px; display: inline-block;"><img style="max-width: 100%; max-height: 100%;" v-bind:src="item.imageUrl? $parent.$parent.changeImgUrl(item.imageUrl) : \'' + '' + "/static/images/diy/crack_figure.png" + '\'" /></div>';
  7. graphicNavPreviewHtml += '<span v-show="item.title" v-bind:style="{ color: data.textColor, opacity: data.textColor ? 1 : 0, marginTop: data.selectedTemplate ==\'imageNavigation\' ? \'10px\' : \'\' }">{{item.title}}</span>';
  8. graphicNavPreviewHtml += '</a>';
  9. graphicNavPreviewHtml += '</div>';
  10. graphicNavPreviewHtml += '</div>';
  11. graphicNavPreviewHtml += '</div>';
  12. Vue.component("graphic-nav", {
  13. data: function () {
  14. return {
  15. id: "graphic_nav_" + get_math_rant(10),
  16. data: this.$parent.data,
  17. list: this.$parent.data.list,
  18. selectedTemplate : this.$parent.data.selectedTemplate
  19. }
  20. },
  21. created: function () {
  22. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  23. this.$parent.data.verify.push(this.verify);//加载验证方法
  24. },
  25. methods: {
  26. verify :function () {
  27. var res = { code: true, message: "" };
  28. return res;
  29. },
  30. },
  31. template: graphicNavPreviewHtml
  32. });
  33. /**
  34. * [图片导航的图片]·组件
  35. */
  36. var graphicNavListHtml = '<div class="graphic-nav-list">';
  37. graphicNavListHtml += '<div class="layui-form-item ns-icon-radio">';
  38. graphicNavListHtml += '<label class="layui-form-label sm">选择模板</label>';
  39. graphicNavListHtml += '<div class="layui-input-block">';
  40. graphicNavListHtml += '<template v-for="(item, index) in selectedTemplateList" v-bind:k="index">';
  41. graphicNavListHtml += '<span :class="[item.value == selectedTemplate ? \'\' : \'layui-hide\']">{{item.name}}</span>';
  42. graphicNavListHtml += '</template>';
  43. graphicNavListHtml += '<ul class="ns-icon">';
  44. graphicNavListHtml += '<li v-for="(item, index) in selectedTemplateList" v-bind:k="index" :class="[item.value == selectedTemplate ? \'ns-text-color ns-border-color ns-bg-color-diaphaneity\' : \'\']" @click="selectedTemplate =item.value">';
  45. graphicNavListHtml += '<img v-if="item.value == selectedTemplate" :src="item.selectedSrc" />'
  46. graphicNavListHtml += '<img v-else :src="item.src" />'
  47. graphicNavListHtml += '</li>';
  48. graphicNavListHtml += '</ul>';
  49. graphicNavListHtml += '</div>';
  50. graphicNavListHtml += '</div>';
  51. graphicNavListHtml += '<div class="layui-form-item ns-icon-radio">';
  52. graphicNavListHtml += '<label class="layui-form-label sm">展示形式</label>';
  53. graphicNavListHtml += '<div class="layui-input-block">';
  54. graphicNavListHtml += '<template v-for="(item, index) in showTypeList" v-bind:k="index">';
  55. graphicNavListHtml += '<span :class="[item.value == data.showType ? \'\' : \'layui-hide\']">{{item.name}}</span>';
  56. graphicNavListHtml += '</template>';
  57. graphicNavListHtml += '<ul class="ns-icon">';
  58. graphicNavListHtml += '<li v-for="(item, index) in showTypeList" v-bind:k="index" :class="[item.value == data.showType ? \'ns-text-color ns-border-color ns-bg-color-diaphaneity\' : \'\']" @click="data.showType = item.value">';
  59. graphicNavListHtml += '<img v-if="item.value == data.showType" :src="item.selectedSrc" />'
  60. graphicNavListHtml += '<img v-else :src="item.src" />'
  61. graphicNavListHtml += '</li>';
  62. graphicNavListHtml += '</ul>';
  63. graphicNavListHtml += '</div>';
  64. graphicNavListHtml += '</div>';
  65. graphicNavListHtml += '<div class="template-edit-wrap">';
  66. graphicNavListHtml += '<ul>';
  67. graphicNavListHtml += '<p class="hint">建议上传尺寸相同的图片(60px * 60px)</p>';
  68. graphicNavListHtml += '<li v-for="(item,index) in list" v-bind:key="index">';
  69. graphicNavListHtml += '<img-sec-upload v-bind:data="{ data: item }" v-bind:condition="$parent.data.selectedTemplate == \'imageNavigation\'"></img-sec-upload>';
  70. graphicNavListHtml += '<div class="content-block" v-bind:class="$parent.data.selectedTemplate">';
  71. graphicNavListHtml += '<div class="layui-form-item">';
  72. graphicNavListHtml += '<label class="layui-form-label sm">标题</label>';
  73. graphicNavListHtml += '<div class="layui-input-block">';
  74. graphicNavListHtml += '<input type="text" name=\'title\' v-model="item.title" class="layui-input" />';
  75. graphicNavListHtml += '</div>';
  76. graphicNavListHtml += '</div>';
  77. graphicNavListHtml += '<sel-link v-bind:data="{ field : $parent.data.list[index].link }"></sel-link>';
  78. graphicNavListHtml += '</div>';
  79. graphicNavListHtml += '<i class="del" v-on:click="list.splice(index,1)" data-disabled="1">x</i>';
  80. graphicNavListHtml += '<div class="error-msg"></div>';
  81. graphicNavListHtml += '</li>';
  82. graphicNavListHtml += '<div class="add-item ns-text-color" v-on:click="list.push({ imageUrl : \'\', title : \'\', link : {} })">';
  83. graphicNavListHtml += '<i>+</i>';
  84. graphicNavListHtml += '<span>添加一个图文导航</span>';
  85. graphicNavListHtml += '</div>';
  86. graphicNavListHtml += '</ul>';
  87. graphicNavListHtml += '</div>';
  88. graphicNavListHtml += '<div class="template-edit-wrap">';
  89. graphicNavListHtml += '<color v-bind:data="{ defaultcolor: \'#666666\' }"></color>';
  90. graphicNavListHtml += '<nav-radius></nav-radius>';
  91. graphicNavListHtml += '</div>';
  92. graphicNavListHtml += '<div class="template-edit-title">';
  93. graphicNavListHtml += '<h3>其他设置</h3>';
  94. graphicNavListHtml += '<i class="layui-icon layui-icon-down" onclick="closeBox(this)"></i>';
  95. graphicNavListHtml += '</div>';
  96. graphicNavListHtml += '<div class="template-edit-wrap">';
  97. graphicNavListHtml += '<color v-bind:data="{ field : \'backgroundColor\', label : \'背景颜色\' }"></color>';
  98. graphicNavListHtml += '<div class="text-slide">';
  99. graphicNavListHtml += '<slide v-bind:data="{ field : \'marginTop\', label : \'页面间距\' }"></slide>';
  100. graphicNavListHtml += '</div>';
  101. graphicNavListHtml += '</div>';
  102. graphicNavListHtml += '</div>';
  103. Vue.component("graphic-nav-list",{
  104. data : function(){
  105. return {
  106. data : this.$parent.data,
  107. showAddItem : true,
  108. list : this.$parent.data.list,
  109. scrollSettingList : [{
  110. name : "固定",
  111. value : "fixed",
  112. max : 5
  113. },{
  114. name : "横向滚动",
  115. value : "horizontal-scroll",
  116. max : 20
  117. }],
  118. scrollSetting : this.$parent.data.scrollSetting,
  119. imageScale : this.$parent.data.imageScale,
  120. padding : this.$parent.data.padding,
  121. selectedTemplate : this.$parent.data.selectedTemplate,
  122. maxTip : 5,//最大上传数量提示
  123. selectedTemplateList : [{
  124. name : '图片导航',
  125. value : 'imageNavigation',
  126. src : graphicNavResourcePath + "/graphic_nav/img/img.png",
  127. selectedSrc: graphicNavResourcePath + "/graphic_nav/img/img_1.png"
  128. },{
  129. name : '文字导航',
  130. value : 'textNavigation',
  131. src : graphicNavResourcePath + "/graphic_nav/img/font.png",
  132. selectedSrc: graphicNavResourcePath + "/graphic_nav/img/font_1.png"
  133. }],
  134. showTypeList: [{
  135. name : '一行三个',
  136. value : '3',
  137. src : graphicNavResourcePath + "/graphic_nav/img/three.png",
  138. selectedSrc: graphicNavResourcePath + "/graphic_nav/img/three_1.png"
  139. }, {
  140. name : '一行四个',
  141. value : '4',
  142. src : graphicNavResourcePath + "/graphic_nav/img/four.png",
  143. selectedSrc: graphicNavResourcePath + "/graphic_nav/img/four_1.png"
  144. }, {
  145. name : '一行五个',
  146. value : '5',
  147. src : graphicNavResourcePath + "/graphic_nav/img/five.png",
  148. selectedSrc: graphicNavResourcePath + "/graphic_nav/img/five_1.png"
  149. }]
  150. };
  151. },
  152. created : function(){
  153. this.changeShowAddItem();
  154. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  155. this.$parent.data.verify.push(this.verify);//加载验证方法
  156. },
  157. watch : {
  158. list : function(){
  159. this.changeShowAddItem();
  160. },
  161. scrollSetting : function(){
  162. //更新父级对象
  163. this.$parent.data.scrollSetting = this.scrollSetting;
  164. //当前滚动方式切换到固定时,要检测当前集合是否超过最多限制max
  165. if(this.scrollSetting == this.scrollSettingList[0].value && this.list.length>this.scrollSettingList[0].max){
  166. this.list.splice(5,this.scrollSettingList[0].max);
  167. }
  168. this.changeShowAddItem();
  169. },
  170. selectedTemplate : function(){
  171. this.$parent.data.selectedTemplate = this.selectedTemplate;
  172. if(this.selectedTemplate == "imageNavigation"){
  173. $(".draggable-element[data-index='" + this.data.index + "'] .graphic-navigation .graphic-nav-list>ul>li input[name='title']").removeAttr("style");
  174. }else{
  175. $(".draggable-element[data-index='" + this.data.index + "'] .graphic-navigation .graphic-nav-list>ul>li .error-msg").text("").hide();
  176. }
  177. }
  178. },
  179. methods : {
  180. //改变图文导航按钮的显示隐藏
  181. changeShowAddItem : function(){
  182. if(this.scrollSetting == this.scrollSettingList[0].value){
  183. if(this.list.length >= this.scrollSettingList[0].max) this.showAddItem = false;
  184. else this.showAddItem = true;
  185. this.maxTip = this.scrollSettingList[0].max;
  186. }else if(this.scrollSetting == this.scrollSettingList[1].value){
  187. if(this.list.length >= this.scrollSettingList[1].max) this.showAddItem = false;
  188. else this.showAddItem = true;
  189. this.maxTip = this.scrollSettingList[1].max;
  190. }
  191. },
  192. //改变图片比例
  193. changeImageScale : function(event){
  194. var v = event.target.value;
  195. if(v != ""){
  196. if(v > 0 && v <= 100){
  197. this.imageScale = v;
  198. this.$parent.data.imageScale = this.imageScale;//更新父级对象
  199. }else{
  200. layer.msg("请输入合法数字1~100");
  201. }
  202. }else{
  203. layer.msg("请输入合法数字1~100");
  204. }
  205. },
  206. //改变上下边距
  207. changePadding : function(event){
  208. var v = event.target.value;
  209. if(v != ""){
  210. if(v >= 0 && v <= 100){
  211. this.padding = v;
  212. this.$parent.data.padding = this.padding;//更新父级对象
  213. }else{
  214. layer.msg("请输入合法数字0~100");
  215. }
  216. }else{
  217. layer.msg("请输入合法数字0~100");
  218. }
  219. },
  220. verify:function () {
  221. var res = { code : true, message : "" };
  222. var _self = this;
  223. $(".draggable-element[data-index='" + this.data.index + "'] .graphic-navigation .graphic-nav-list .template-edit-wrap>ul>li").each(function(index){
  224. if(_self.selectedTemplate == "imageNavigation"){
  225. $(this).find("input[name='title']").removeAttr("style");//清空输入框的样式
  226. //检测是否有未上传的图片
  227. if(_self.list[index].imageUrl == ""){
  228. res.code = false;
  229. res.message = "请选择一张图片";
  230. $(this).find(".error-msg").text("请选择一张图片").show();
  231. return res;
  232. }else{
  233. $(this).find(".error-msg").text("").hide();
  234. }
  235. }else{
  236. if(_self.list[index].title == ""){
  237. res.code = false;
  238. res.message = "请输入标题";
  239. $(this).find("input[name='title']").attr("style","border-color:red !important;").focus();
  240. $(this).find(".error-msg").text("请输入标题").show();
  241. return res;
  242. }else{
  243. $(this).find("input[name='title']").removeAttr("style");
  244. $(this).find(".error-msg").text("").hide();
  245. }
  246. }
  247. });
  248. return res;
  249. }
  250. },
  251. template : graphicNavListHtml
  252. });
  253. var navRadiusHtml = '<div class="layui-form-item ns-icon-radio">';
  254. navRadiusHtml += '<label class="layui-form-label sm">圆角展示</label>';
  255. navRadiusHtml += '<div class="layui-input-block">';
  256. navRadiusHtml += '<template v-for="(item, index) in navRadius" v-bind:k="index">';
  257. navRadiusHtml += '<span :class="[item.value == data.navRadius ? \'\' : \'layui-hide\']">{{item.text}}</span>';
  258. navRadiusHtml += '</template>';
  259. navRadiusHtml += '<ul class="ns-icon">';
  260. navRadiusHtml += '<li v-for="(item, index) in navRadius" v-bind:k="index" :class="[item.value == data.navRadius ? \'ns-text-color ns-border-color ns-bg-color-diaphaneity\' : \'\']" @click="data.navRadius=item.value">';
  261. navRadiusHtml += '<img v-if="item.value == data.navRadius" :src="item.selectedSrc" />'
  262. navRadiusHtml += '<img v-else :src="item.src" />'
  263. navRadiusHtml += '</li>';
  264. navRadiusHtml += '</ul>';
  265. navRadiusHtml += '</div>';
  266. navRadiusHtml += '</div>';
  267. Vue.component("nav-radius",{
  268. template : navRadiusHtml,
  269. data : function(){
  270. return {
  271. data : this.$parent.data,
  272. navRadius: [
  273. {
  274. text: "直角",
  275. value: "right-angle",
  276. src: graphicNavResourcePath + "/graphic_nav/img/right-angle.png",
  277. selectedSrc: graphicNavResourcePath + "/graphic_nav/img/right-angle_1.png"
  278. },
  279. {
  280. text: "圆角",
  281. value: "fillet",
  282. src: graphicNavResourcePath + "/graphic_nav/img/fillet.png",
  283. selectedSrc: graphicNavResourcePath + "/graphic_nav/img/fillet_1.png"
  284. }
  285. ],
  286. }
  287. },
  288. created : function(){
  289. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  290. this.$parent.data.verify.push(this.verify);//加载验证方法
  291. },
  292. methods : {
  293. verify :function () {
  294. var res = {code: true, message: ""};
  295. return res;
  296. },
  297. },
  298. });