style.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /**
  2. * 空的验证组件,后续如果增加业务,则更改组件
  3. */
  4. var emptyHtml = '<div class="text-slide">';
  5. emptyHtml += '<slide v-bind:data="{ field : \'marginTop\', label : \'页面间距\' }"></slide>';
  6. // emptyHtml += '<slide v-bind:data="{ field : \'padding\', label : \'上下边距\' }"></slide>';
  7. emptyHtml += '</div>';
  8. var styleHtml = '<div class="layui-form-item">';
  9. styleHtml += '<label class="layui-form-label sm">模板样式</label>';
  10. styleHtml += '<div class="layui-input-block" style="margin-left: 100px;">';
  11. styleHtml += '<div v-if="data.styleName" class="ns-input-text ns-text-color selected-style" v-on:click="selectTestStyle">{{data.styleName}} <i class="layui-icon layui-icon-right"></i></div>';
  12. styleHtml += '<div v-else class="ns-input-text selected-style" style="color: #323233;" v-on:click="selectTestStyle">选择 <i class="layui-icon layui-icon-right"></i></div>';
  13. styleHtml += '</div>';
  14. styleHtml += '</div>';
  15. Vue.component("text-empty", {
  16. template: emptyHtml,
  17. data: function () {
  18. return {
  19. data : this.$parent.data,
  20. marginTop: this.$parent.data.marginTop,
  21. }
  22. },
  23. created:function() {
  24. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  25. this.$parent.data.verify.push(this.verify);//加载验证方法
  26. },
  27. methods: {
  28. verify : function () {
  29. var res = { code : true, message : "" };
  30. var _self = this;
  31. if(this.data.title.length == 0){
  32. res.code = false;
  33. res.message = "文本不能为空";
  34. setTimeout(function(){
  35. $("#title_" + _self.data.index).focus();
  36. },10);
  37. }
  38. return res;
  39. },
  40. }
  41. });
  42. Vue.component("text-style", {
  43. template: styleHtml,
  44. data: function() {
  45. return {
  46. data: this.$parent.data,
  47. }
  48. },
  49. created:function() {
  50. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  51. this.$parent.data.verify.push(this.verify);//加载验证方法
  52. },
  53. methods: {
  54. verify: function () {
  55. var res = { code: true, message: "" };
  56. return res;
  57. },
  58. selectTestStyle: function() {
  59. var self = this;
  60. layer.open({
  61. type: 1,
  62. title: '风格选择',
  63. area:['930px','630px'],
  64. btn: ['确定', '返回'],
  65. content: $(".draggable-element[data-index='" + self.data.index + "'] .edit-attribute .style-list-box").html(),
  66. success: function(layero, index) {
  67. $(".layui-layer-content input[name='style']").val(self.data.style);
  68. $(".layui-layer-content input[name='sub']").val(self.data.sub);
  69. $(".layui-layer-content input[name='style_name']").val(self.data.styleName);
  70. $("body").on("click", ".layui-layer-content .style-list-con .style-li", function () {
  71. $(this).addClass("selected ns-border-color").siblings().removeClass("selected ns-border-color ns-bg-color-after");
  72. $(".layui-layer-content input[name='style']").val($(this).index() + 1);
  73. $(".layui-layer-content input[name='sub']").val($(this).find("input").val());
  74. $(".layui-layer-content input[name='style_name']").val($(this).find("span").text());
  75. });
  76. },
  77. yes: function (index, layero) {
  78. self.data.style = $(".layui-layer-content input[name='style']").val();
  79. self.data.sub = $(".layui-layer-content input[name='sub']").val();
  80. self.data.styleName = $(".layui-layer-content input[name='style_name']").val();
  81. layer.closeAll()
  82. }
  83. });
  84. },
  85. /* fontWeight: function(data, obj) {
  86. var self = this;
  87. self.data.fontWeight = data;
  88. $(obj).attr("checked", true);
  89. $(obj).siblings().attr("checked", false);
  90. layui.use('form', function(){
  91. form = layui.form;
  92. form.render();
  93. })
  94. } */
  95. }
  96. });
  97. // 文本对齐方式
  98. /* var textAlignStyle = '<div class="layui-form-item ns-icon-radio">'
  99. textAlignStyle += '<label class="layui-form-label sm">对齐方式</label>';
  100. textAlignStyle += '<div class="layui-input-block">';
  101. textAlignStyle += '<template v-for="(item, index) in alignStyleList" v-bind:k="index">';
  102. textAlignStyle += '<span :class="[item.className == data.alignStyle ? \'\' : \'layui-hide\']">{{item.name}}</span>';
  103. textAlignStyle += '</template>';
  104. textAlignStyle += '<ul class="ns-icon">';
  105. textAlignStyle += '<li v-for="(item, index) in alignStyleList" v-bind:k="index" :class="[item.className == data.alignStyle ? \'ns-text-color ns-border-color ns-bg-color-diaphaneity\' : \'\']" @click="changeSelectedStyle(index)">';
  106. textAlignStyle += '<img v-if="item.className == data.alignStyle" :src="item.selectedSrc" />';
  107. textAlignStyle += '<img v-else :src="item.src" />';
  108. textAlignStyle += '</li>';
  109. textAlignStyle += '</ul>';
  110. textAlignStyle += '</div>';
  111. textAlignStyle += '</div>';
  112. Vue.component("text-align-style", {
  113. template: textAlignStyle,
  114. data: function () {
  115. return {
  116. data: this.$parent.data,
  117. alignStyleList: [] // 对齐方式集合
  118. };
  119. },
  120. created: function () {
  121. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  122. this.$parent.data.verify.push(this.verify);//加载验证方法
  123. this.initAlignStyleList();
  124. },
  125. methods: {
  126. verify : function () {
  127. var res = { code : true, message : "" };
  128. return res;
  129. },
  130. initAlignStyleList: function () {
  131. var prefix = textResourcePath + "/text/img";
  132. this.alignStyleList.push({name: "居左", src: prefix+ "/left.png", selectedSrc: prefix+ "/left_1.png", className: "left"});
  133. this.alignStyleList.push({name: "居中", src: prefix+ "/center.png", selectedSrc: prefix+ "/center_1.png", className: "center"});
  134. this.alignStyleList.push({name: "居右", src: prefix+ "/right.png", selectedSrc: prefix+ "/right_1.png", className: "right"});
  135. },
  136. changeSelectedStyle: function(index) {
  137. for (var i=0; i<this.alignStyleList.length; i++) {
  138. if (i == index) {
  139. this.data.alignStyle = this.alignStyleList[i].className;
  140. }
  141. }
  142. }
  143. },
  144. }); */
  145. // 主标题文字粗细
  146. var fontWeightHtml = '<div class="layui-form-item ns-icon-radio">';
  147. fontWeightHtml += '<label class="layui-form-label sm">文字粗细</label>';
  148. fontWeightHtml += '<div class="layui-input-block">';
  149. fontWeightHtml += '<template v-for="(item, index) in alignStyleList" v-bind:k="index">';
  150. fontWeightHtml += '<span :class="[item.className == data.fontWeight ? \'\' : \'layui-hide\']">{{item.name}}</span>';
  151. fontWeightHtml += '</template>';
  152. fontWeightHtml += '<ul class="ns-icon">';
  153. fontWeightHtml += '<li v-for="(item, index) in alignStyleList" v-bind:k="index" :class="[item.className == data.fontWeight ? \'ns-text-color ns-border-color ns-bg-color-diaphaneity\' : \'\']" @click="changeSelectedStyle(index)">';
  154. fontWeightHtml += '<img v-if="item.className == data.fontWeight" :src="item.selectedSrc" />'
  155. fontWeightHtml += '<img v-else :src="item.src" />'
  156. fontWeightHtml += '</li>';
  157. fontWeightHtml += '</ul>';
  158. fontWeightHtml += '</div>';
  159. fontWeightHtml += '</div>';
  160. Vue.component("font-weight", {
  161. template: fontWeightHtml,
  162. data: function () {
  163. return {
  164. data: this.$parent.data,
  165. alignStyleList: [] // 对齐方式集合
  166. };
  167. },
  168. created: function () {
  169. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  170. this.$parent.data.verify.push(this.verify);//加载验证方法
  171. this.initAlignStyleList();
  172. },
  173. methods: {
  174. verify : function () {
  175. var res = { code : true, message : "" };
  176. return res;
  177. },
  178. initAlignStyleList: function () {
  179. var prefix = textResourcePath + "/text/img";
  180. this.alignStyleList.push({name: "粗", src: prefix+ "/blod.png", selectedSrc: prefix+ "/blod_1.png", className: "600"});
  181. this.alignStyleList.push({name: "细", src: prefix+ "/normal.png", selectedSrc: prefix+ "/normal_1.png", className: "500"});
  182. },
  183. changeSelectedStyle: function(index) {
  184. for (var i=0; i<this.alignStyleList.length; i++) {
  185. if (i == index) {
  186. this.data.fontWeight = this.alignStyleList[i].className;
  187. }
  188. }
  189. }
  190. },
  191. });
  192. // 是否启用更多按钮设置
  193. var moreBtnHtml = '<div class="layui-form-item ns-checkbox-wrap">';
  194. moreBtnHtml += '<label class="layui-form-label sm">是否启用</label>';
  195. moreBtnHtml += '<div class="layui-input-block">';
  196. moreBtnHtml += '<span v-if="data.isShowMore == 1">是</span>';
  197. moreBtnHtml += '<span v-else>否</span>';
  198. moreBtnHtml += '<div v-on:click="changeState()" class="layui-unselect layui-form-checkbox" v-bind:class="{ \'layui-form-checked\': (data.isShowMore==1) }" lay-skin="primary"><i class="layui-icon layui-icon-ok"></i></div>';
  199. moreBtnHtml += '</div>';
  200. moreBtnHtml += '</div>';
  201. Vue.component("text-more-btn", {
  202. template: moreBtnHtml,
  203. data: function () {
  204. return {
  205. data: this.$parent.data,
  206. };
  207. },
  208. created: function () {
  209. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  210. this.$parent.data.verify.push(this.verify);//加载验证方法
  211. },
  212. methods: {
  213. verify : function () {
  214. var res = { code : true, message : "" };
  215. return res;
  216. },
  217. changeState: function() {
  218. this.data.isShowMore = this.data.isShowMore ? 0 : 1;
  219. }
  220. },
  221. });
  222. // 文字大小
  223. var textFontSizeHtml = '<div class="layui-form-item ns-icon-radio">';
  224. textFontSizeHtml += '<label class="layui-form-label sm">{{data.label}}</label>';
  225. textFontSizeHtml += '<div class="layui-input-block">';
  226. textFontSizeHtml += '<template v-for="(item, index) in list" v-bind:k="index">';
  227. textFontSizeHtml += '<span :class="[item.value == parent[data.field] ? \'\' : \'layui-hide\']">{{item.value}}px</span>';
  228. textFontSizeHtml += '</template>';
  229. textFontSizeHtml += '<ul class="ns-icon">';
  230. textFontSizeHtml += '<li v-for="(item, index) in list" v-bind:k="index" :class="[item.value == parent[data.field] ? \'ns-text-color ns-border-color ns-bg-color-diaphaneity\' : \'\']" :title="item.value + \'px\'" @click="parent[data.field] = item.value">';
  231. textFontSizeHtml += '<img v-if="item.value == parent[data.field]" :src="item.selectedSrc" />'
  232. textFontSizeHtml += '<img v-else :src="item.src" />'
  233. textFontSizeHtml += '</li>';
  234. textFontSizeHtml += '</ul>';
  235. textFontSizeHtml += '</div>';
  236. textFontSizeHtml += '</div>';
  237. Vue.component("text-font-size", {
  238. template: textFontSizeHtml,
  239. props: {
  240. data: {
  241. type: Object,
  242. default: function () {
  243. return {
  244. field: "fontSize",
  245. label: "文字大小",
  246. max: 16
  247. };
  248. }
  249. }
  250. },
  251. data: function () {
  252. return {
  253. list: [],
  254. parent: this.$parent.data,
  255. };
  256. },
  257. created: function () {
  258. if (this.data.label == undefined) this.data.label = "文字大小";
  259. if (this.data.field == undefined) this.data.field = "fontSize";
  260. if (this.data.max == undefined) this.data.max = "16";
  261. if (this.data.max == 12) {
  262. this.list = [{label: "小", value: "12", src: textResourcePath + "/text/img/font_12.png", selectedSrc: textResourcePath + "/text/img/font_12_1.png"}];
  263. } else if (this.data.max == 14) {
  264. this.list = [
  265. {label: "小", value: "12", src: textResourcePath + "/text/img/font_12.png", selectedSrc: textResourcePath + "/text/img/font_12_1.png"},
  266. {label: "中", value: "14", src: textResourcePath + "/text/img/font_14.png", selectedSrc: textResourcePath + "/text/img/font_14_1.png"}
  267. ]
  268. } else {
  269. this.list = [
  270. {label: "小", value: "12", src: textResourcePath + "/text/img/font_12.png", selectedSrc: textResourcePath + "/text/img/font_12_1.png"},
  271. {label: "中", value: "14", src: textResourcePath + "/text/img/font_14.png", selectedSrc: textResourcePath + "/text/img/font_14_1.png"},
  272. {label: "大", value: "16", src: textResourcePath + "/text/img/font_16.png", selectedSrc: textResourcePath + "/text/img/font_16_1.png"}
  273. ];
  274. }
  275. },
  276. watch: {
  277. data: function (val, oldVal) {
  278. if (val.field == undefined) val.field = oldVal.field;
  279. if (val.label == undefined) val.label = "文字大小";
  280. if (val.max == undefined) val.max = "16";
  281. },
  282. }
  283. });