style.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. var floatBtnListHtml = '<div class="float-btn-list">';
  2. floatBtnListHtml += '<p class="hint" style="font-size: 12px; margin: 5px 0 8px;">建议上传正方形图片,大小建议为33px * 33px</p>';
  3. floatBtnListHtml += '<ul>';
  4. floatBtnListHtml += '<li v-for="(item,index) in list" v-bind:key="index">';
  5. floatBtnListHtml += '<img-sec-upload v-bind:data="{data : item}" :currIndex = "index"></img-sec-upload>';
  6. floatBtnListHtml += '<div class="content-block">';
  7. floatBtnListHtml += '<template v-for="(titem,index) in typeList" v-bind:k="index">';
  8. floatBtnListHtml += '<div v-on:click="item.linktype=titem.value" v-bind:class="{ \'layui-unselect layui-form-radio\' : true,\'layui-form-radioed\' : (item.linktype==titem.value) }"><i class="layui-anim layui-icon">&#xe63f;</i><div>{{titem.text}}</div></div>';
  9. floatBtnListHtml += '</template>';
  10. floatBtnListHtml += '<sel-link v-bind:data="{field: $parent.data.list[index].link}" v-if="item.linktype==\'link\'"></sel-link>';
  11. floatBtnListHtml += '</div>';
  12. floatBtnListHtml += '<i class="del" v-on:click="list.splice(index,1)" data-disabled="1">x</i>';
  13. floatBtnListHtml += '<div class="error-msg"></div>';
  14. floatBtnListHtml += '</li>';
  15. floatBtnListHtml += '</ul>';
  16. floatBtnListHtml += '<div class="add-item ns-text-color" v-if="showAddItem" v-on:click="list.push({ imageUrl : \'\', title : \'\', link : {}, linktype: \'link\' })">';
  17. floatBtnListHtml += '<i>+</i>';
  18. floatBtnListHtml += '<span>添加一个浮动按钮</span>';
  19. floatBtnListHtml += '</div>';
  20. // floatBtnListHtml += '<div class="add-item ns-text-color" v-if="showAddItem && ($parent.data.bottomPosition== 3 || $parent.data.bottomPosition == 4)" v-on:click="list.splice(0,0,{ imageUrl : \'\', title : \'\', link : {} })">';
  21. // floatBtnListHtml += '<i>+</i>';
  22. // floatBtnListHtml += '<span>添加一个浮动按钮</span>';
  23. // floatBtnListHtml += '</div>';
  24. floatBtnListHtml += '</div>';
  25. Vue.component("float-btn-list", {
  26. data: function () {
  27. return {
  28. list: this.$parent.data.list,
  29. maxTip: 3,//最大上传数量提示
  30. showAddItem: true,
  31. systemInfo: {
  32. top: 0,
  33. left: 0,
  34. right: 0,
  35. bottom: 0,
  36. width: 0
  37. },
  38. screenWidth: 0,
  39. typeList: [
  40. {
  41. text: "链接",
  42. value: "link"
  43. },
  44. {
  45. text: "返回顶部",
  46. value: "gotop"
  47. },
  48. {
  49. text: "客服",
  50. value: "custom"
  51. }
  52. ]
  53. };
  54. },
  55. created: function () {
  56. if (!this.$parent.data.verify) this.$parent.data.verify = [];
  57. this.$parent.data.verify.push(this.verify);//加载验证方法
  58. this.getElementPosition(this.$parent);
  59. // window.addEventListener('resize', onResize);
  60. window.onresize = () => {
  61. return (() => {
  62. window.screenWidth = document.body.clientWidth
  63. this.screenWidth = window.screenWidth
  64. })()
  65. }
  66. this.changeShowAddItem();//获取默认值
  67. },
  68. watch: {
  69. list: function () {
  70. this.changeShowAddItem();
  71. },
  72. screenWidth(val) {
  73. // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
  74. this.getElementPosition(this.$parent)
  75. }
  76. },
  77. methods: {
  78. verify: function () {
  79. var res = { code: true, message: "" };
  80. if (this.list.length > 0) {
  81. for (var i = 0; i < this.list.length; i++) {
  82. if (this.$parent.data.list[i].imageUrl == "") {
  83. res.code = false;
  84. res.message = "请添加图片";
  85. break;
  86. }
  87. }
  88. } else {
  89. res.code = false;
  90. res.message = "请添加一个浮动按钮";
  91. }
  92. return res;
  93. },
  94. //改变添加浮动按钮
  95. changeShowAddItem() {
  96. if (this.list.length >= this.maxTip) this.showAddItem = false;
  97. else this.showAddItem = true;
  98. },
  99. getElementPosition(e) {
  100. var box = document.querySelector("#viewWrap").getBoundingClientRect()
  101. var box1 = document.querySelector(".screen_center").getBoundingClientRect();
  102. if (this.$parent.data.bottomPosition == 2) {
  103. // this.$parent.data.baseBtnBottom = Math.abs(box1.top) + 20;
  104. this.$parent.data.baseBtnBottom = 150;
  105. var temp = 150 + parseInt(this.$parent.data.btnBottom);
  106. $(".draggable-element .float-btn").css({
  107. left: box1.left + 285,
  108. top: temp,
  109. 'margin-right': '15px',
  110. 'z-index': 999,
  111. height: '40px'
  112. });
  113. }
  114. else if (this.$parent.data.bottomPosition == 3) {
  115. this.$parent.data.baseBtnBottom = 250
  116. // var temp = 250 + parseInt(this.$parent.data.btnBottom)
  117. var temp = 270;
  118. $(".draggable-element .float-btn").css({
  119. left: box1.left - 30,
  120. top: 'auto',
  121. bottom: temp,
  122. 'z-index': 999
  123. });
  124. } else if (this.$parent.data.bottomPosition == 1) {
  125. this.$parent.data.baseBtnBottom = Math.abs(box.top) + 20;
  126. // var temp = Math.abs(box1.top) + parseInt(this.$parent.data.btnBottom) + 20;
  127. var temp = 150 + parseInt(this.$parent.data.btnBottom);
  128. $(".draggable-element .float-btn").css({
  129. left: box1.left,
  130. top: temp,
  131. 'z-index': 999,
  132. height: '40px'
  133. });
  134. } else {
  135. this.$parent.data.baseBtnBottom = 250
  136. var temp = 250 + parseInt(this.$parent.data.btnBottom)
  137. $(".draggable-element .float-btn").css({
  138. left: box1.left + 285,
  139. top: 'auto',
  140. bottom: temp,
  141. 'margin-right': '15px',
  142. 'z-index': 999
  143. });
  144. }
  145. $(".draggable-element .float-btn .edit-attribute").css({
  146. position: 'fixed',
  147. right: '30px',
  148. top: Math.abs(box.top),
  149. })
  150. }
  151. },
  152. template: floatBtnListHtml
  153. });
  154. var searchHtml = '<div class="layui-form-item flex">';
  155. searchHtml += '<div class="flex_left">';
  156. searchHtml += '<label class="layui-form-label sm">{{data.label}}</label>';
  157. searchHtml += '<template v-for="(item,index) in list" v-bind:k="index">';
  158. searchHtml += '<div v-if="parent[data.field]==item.value">{{item.label}}</div>';
  159. searchHtml += '</template>';
  160. searchHtml += '</div>';
  161. searchHtml += '<div class="layui-input-block flex_fill">';
  162. searchHtml += '<div class="flex_choose">';
  163. searchHtml += '<template v-for="(item,index) in list" v-bind:k="index">';
  164. // searchHtml += '<div v-on:click="parent[data.field]=item.value" v-bind:class="{ \'layui-unselect layui-form-radio\' : true,\'layui-form-radioed\' : (parent[data.field]==item.value) }"><i class="layui-anim layui-icon">&#xe63f;</i><div>{{item.label}}</div></div>';
  165. searchHtml += '<div v-on:click="parent[data.field]=item.value" :class="{\'active\':parent[data.field]==item.value}">';
  166. searchHtml += '<img :src="item.icon_img_active" v-if="parent[data.field]==item.value"/>';
  167. searchHtml += '<img :src="item.icon_img" v-else />';
  168. searchHtml += '</div>';
  169. searchHtml += '</template>';
  170. searchHtml += '</div>';
  171. searchHtml += '</div>';
  172. searchHtml += '</div>';
  173. Vue.component("btn-position", {
  174. props: {
  175. data: {
  176. type: Object,
  177. default: function () {
  178. return {
  179. field: "textAlign",
  180. label: "文本位置"
  181. };
  182. }
  183. }
  184. },
  185. data: function () {
  186. return {
  187. list: [
  188. {
  189. label: "居左",
  190. value: "left",
  191. icon_img:floatBtnResourcePath + "/search/img/text_left.png",
  192. icon_img_active:floatBtnResourcePath + "/search/img/text_left_hover.png"
  193. },
  194. {
  195. label: "居右",
  196. value: "center",
  197. icon_img:floatBtnResourcePath + "/search/img/text_right.png",
  198. icon_img_active:floatBtnResourcePath + "/search/img/text_right_hover.png"
  199. },
  200. ],
  201. parent: this.$parent.data,
  202. };
  203. },
  204. created: function () {
  205. if(!this.$parent.data.verify) this.$parent.data.verify = [];
  206. this.$parent.data.verify.push(this.verify);//加载验证方法
  207. if (this.data.label == undefined) this.data.label = "文本位置";
  208. if (this.data.field == undefined) this.data.field = "textAlign";
  209. var self = this;
  210. setTimeout(function () {
  211. layui.use(['form'], function() {
  212. self.form = layui.form;
  213. self.form.render();
  214. });
  215. },10);
  216. },
  217. watch: {
  218. data: function (val, oldVal) {
  219. if (val.field == undefined) val.field = oldVal.field;
  220. if (val.label == undefined) val.label = "文本位置";
  221. },
  222. },
  223. methods: {
  224. verify : function () {
  225. var res = { code : true, message : "" };
  226. return res;
  227. },
  228. },
  229. template: searchHtml
  230. });
  231. /**
  232. * 按钮位置
  233. */
  234. var btnPosition = '<div class="layui-form-item ns-icon-radio">';
  235. btnPosition += '<label class="layui-form-label sm">{{data.label}}</label>';
  236. btnPosition += '<div class="layui-input-block">';
  237. btnPosition += '<template v-for="(item,index) in list" v-bind:k="index" :key="index">';
  238. btnPosition += '<span :class="[parent[data.field] == item.value ? \'\' : \'layui-hide\']">{{item.label}}</span>';
  239. btnPosition += '</template>';
  240. btnPosition += '<ul class="ns-icon">';
  241. btnPosition += '<template v-for="(item,index) in list" v-bind:k="index" :key="index">';
  242. // searchHtml += '<div v-on:click="parent[data.field]=item.value" v-bind:class="{ \'layui-unselect layui-form-radio\' : true,\'layui-form-radioed\' : (parent[data.field]==item.value) }"><i class="layui-anim layui-icon">&#xe63f;</i><div>{{item.label}}</div></div>';
  243. btnPosition += '<li v-on:click="clickFun(item.value)" :class="{\'ns-text-color ns-border-color ns-bg-color-diaphaneity\':parent[data.field] == item.value}">';
  244. btnPosition += '<img :src="item.icon_img_active" v-if="parent[data.field] == item.value"/>';
  245. btnPosition += '<img :src="item.icon_img" v-else />';
  246. btnPosition += '</li>';
  247. btnPosition += '</template>';
  248. btnPosition += '</ul>';
  249. btnPosition += '</div>';
  250. btnPosition += '</div>';
  251. Vue.component("btn-position", {
  252. props: {
  253. data: {
  254. type: Object,
  255. default: function () {
  256. return {
  257. field: "bottomPosition",
  258. label: "按钮位置"
  259. };
  260. }
  261. }
  262. },
  263. data: function () {
  264. return {
  265. list: [
  266. {
  267. label: "左上",
  268. value: "1",
  269. icon_img: floatBtnResourcePath + "/float_btn/img/left_top.png",
  270. icon_img_active: floatBtnResourcePath + "/float_btn/img/left_top_hover.png"
  271. },
  272. {
  273. label: "右上",
  274. value: "2",
  275. icon_img: floatBtnResourcePath + "/float_btn/img/right_top.png",
  276. icon_img_active: floatBtnResourcePath + "/float_btn/img/right_top_hover.png"
  277. },
  278. {
  279. label: "左下",
  280. value: "3",
  281. icon_img: floatBtnResourcePath + "/float_btn/img/left_bottom.png",
  282. icon_img_active: floatBtnResourcePath + "/float_btn/img/left_bottom_hover.png"
  283. },
  284. {
  285. label: "右下",
  286. value: "4",
  287. icon_img: floatBtnResourcePath + "/float_btn/img/right_bottom.png",
  288. icon_img_active: floatBtnResourcePath + "/float_btn/img/right_bottom_hover.png"
  289. },
  290. ],
  291. isReverse: true,
  292. parent: this.$parent.data,
  293. imglist: this.$parent.data.list,
  294. bottomPos: 1,
  295. };
  296. },
  297. created: function () {
  298. if (!this.$parent.data.verify) this.$parent.data.verify = [];
  299. this.$parent.data.verify.push(this.verify);//加载验证方法
  300. if (this.data.label == undefined) this.data.label = "按钮位置";
  301. if (this.data.field == undefined) this.data.field = "bottomPosition";
  302. if (this.data.value == undefined) { this.data.value = 1 }
  303. if (this.parent[this.data.field] == undefined) { this.parent[this.data.field] = 1 }
  304. this.bottomPos = this.parent.bottomPosition
  305. var self = this;
  306. setTimeout(function () {
  307. layui.use(['form'], function () {
  308. self.form = layui.form;
  309. self.form.render();
  310. });
  311. }, 10);
  312. },
  313. watch: {
  314. data: function (val, oldVal) {
  315. if (val.field == undefined) val.field = oldVal.field;
  316. if (val.label == undefined) val.label = "按钮位置";
  317. },
  318. imglist: function (val, oldVal) {
  319. var height = val.length > 1 ? ((val.length - 1) * 50) + 40 : 40
  320. $(".draggable-element .float-btn").css({
  321. height: height
  322. });
  323. $(".float-btn .float-btn-box").css({
  324. height: height
  325. })
  326. },
  327. bottomPos: function (val, oldVal) {
  328. if ((oldVal == 3 || oldVal == 4) && (val == 1 || val == 2) || (oldVal == 1 || oldVal == 2) && (val == 3 || val == 4)) {
  329. this.imglist = this.imglist.reverse()
  330. }
  331. }
  332. },
  333. methods: {
  334. clickFun: function (val) {
  335. this.bottomPos = val;
  336. this.parent[this.data.field] = val
  337. this.getElementPosition(this.parent)
  338. },
  339. verify: function () {
  340. var res = { code: true, message: "" };
  341. return res;
  342. },
  343. getElementPosition(e) {
  344. var box = document.querySelector("#viewWrap").getBoundingClientRect()
  345. var box1 = document.querySelector(".screen_center").getBoundingClientRect();
  346. if (this.parent.bottomPosition == 2) {
  347. // this.parent.baseBtnBottom = box1.top + 20;
  348. this.parent.baseBtnBottom = 150;
  349. // var temp = parseInt(box1.top) + parseInt(this.parent.btnBottom) + 20;
  350. var temp = 150 + parseInt(this.parent.btnBottom);
  351. console.log('baseBtnBottom2', temp);
  352. $(".draggable-element .float-btn").css({
  353. left: box1.left + 285,
  354. top: temp,
  355. });
  356. }
  357. else if (this.parent.bottomPosition == 3) {
  358. this.parent.baseBtnBottom = 250
  359. var temp = 250 + parseInt(this.parent.btnBottom)
  360. $(".draggable-element .float-btn").css({
  361. left: box1.left - 30,
  362. top: 'auto',
  363. bottom: temp,
  364. 'z-index': 999
  365. });
  366. } else if (this.parent.bottomPosition == 1) {
  367. // this.parent.baseBtnBottom = box1.top + 20;
  368. this.parent.baseBtnBottom = 150;
  369. // var temp = parseInt(box1.top) + parseInt(this.parent.btnBottom) + 20;
  370. var temp = 150 + parseInt(this.parent.btnBottom);
  371. console.log('baseBtnBottom1', temp);
  372. $(".draggable-element .float-btn").css({
  373. left: box1.left - 30,
  374. top: temp
  375. });
  376. } else {
  377. this.parent.baseBtnBottom = 250
  378. var temp = 250 + parseInt(this.parent.btnBottom)
  379. $(".draggable-element .float-btn").css({
  380. left: box1.left + 285,
  381. top: 'auto',
  382. bottom: temp,
  383. 'margin-right': '15px',
  384. 'z-index': 999
  385. });
  386. }
  387. // }
  388. $(".draggable-element .float-btn .edit-attribute").css({
  389. position: 'fixed',
  390. right: '30px',
  391. top: Math.abs(box.top),
  392. })
  393. }
  394. },
  395. template: btnPosition
  396. });