diy-main-page.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template id="diy-main-page">
  2. <div>
  3. <diy-style-contain title="背景设置">
  4. <el-form ref="form" :model="form" label-width="80px" style="margin-top: 20px;">
  5. <el-form-item label="页面风格">
  6. <div>标准</div>
  7. </el-form-item>
  8. <el-form-item label="底部颜色">
  9. <el-color-picker v-model="form.defColor" @change="updateColor"></el-color-picker>
  10. </el-form-item>
  11. <el-form-item label="背景图片">
  12. <div class="bg-img-box" v-show="isShowDefBg">
  13. <div class="bg-img-item" @click="bgChange('')">
  14. <div class=" bg-img" :class="!defBg?'active-img':''"></div>
  15. <span class="img-text">空</span>
  16. </div>
  17. <div v-for="(item,index) in defBgList" :key="item.type" class="bg-img-item" @click="bgChange(item.url)">
  18. <image :src="static_img_prefix+item.url" class="bg-img" :class="defBg == item.url?'active-img':''">
  19. <span class="img-text">背景样式{{item.type}}</span>
  20. </div>
  21. </div>
  22. <diy-img-setting :img-infos="form.imageUrl" def-img-count="1" :show-url="false" :suggest-site="2" suggest-size-text="建议尺寸:宽750x高度不限" :img-contain-style="{padding: 0}" :show-title="false" @change="addIconImg"></diy-img-setting>
  23. </el-form-item>
  24. </diy-style-contain>
  25. <diy-size-setting
  26. top-name="边距"
  27. style="border: none"
  28. :size-infos="sizeInfos"
  29. :size-infos-value="sizeInfosValue"
  30. :max-value="25"
  31. @chang="paddingChange"
  32. ></diy-size-setting>
  33. </div>
  34. </template>
  35. <script>
  36. Vue.component('diy-main-page', {
  37. name: "diy-main-page",
  38. template: '#diy-main-page',
  39. props: {
  40. mainPage: {
  41. type: Object,
  42. default () {
  43. return {}
  44. }
  45. },
  46. },
  47. data() {
  48. return {
  49. static_img_prefix: '<?= Yii::getAlias('@attachurl') ?>'+'/static',
  50. form: {
  51. name: '',
  52. type: '纯色',
  53. imgUrl:'',
  54. imageUrl: [],
  55. defColor: '',
  56. paddingTop: 0,
  57. paddingBottom: 0,
  58. paddingLeft: 0,
  59. paddingRight: 0
  60. },
  61. sizeInfos: ['上边距', '下边距', '左右边距'],
  62. // 页面内边距
  63. sizeInfosValue: [0, 0, 0],
  64. defBg:'',
  65. defBgList:[{
  66. type:'1',
  67. url:'/diy/nav/bg1.png'
  68. },{
  69. type:'2',
  70. url:'/diy/nav/bg2.png'
  71. },{
  72. type:'3',
  73. url:'/diy/nav/bg3.png'
  74. },{
  75. type:'4',
  76. url:'/diy/nav/bg4.png'
  77. },{
  78. type:'5',
  79. url:'/diy/nav/bg5.png'
  80. }]
  81. }
  82. },
  83. computed: {
  84. isShowDefBg() {
  85. return this.mainPage.diytemplate =='user_center'
  86. }
  87. },
  88. created() {
  89. this.init()
  90. },
  91. methods: {
  92. init() {
  93. console.log('data------------',this)
  94. let data = deepClone(this.mainPage)
  95. this.sizeInfosValue = [parseInt(data.paddingTop),parseInt(data.paddingBottom),parseInt(data.paddingLeft)]
  96. if (data.imgUrl) {
  97. if (data.imgUrl.indexOf('http') ==-1){
  98. this.defBg = data.imgUrl
  99. } else {
  100. this.defBg = 'diy'
  101. data.imageUrl = [{
  102. imgUrl: data.imgUrl
  103. }]
  104. }
  105. } else {
  106. data.imageUrl = []
  107. }
  108. this.form = data
  109. },
  110. handleChange(val) {
  111. console.log(val);
  112. },
  113. radioChange() {
  114. this.update()
  115. },
  116. updateColor(colors) {
  117. this.update()
  118. },
  119. nameChange() {
  120. this.update()
  121. },
  122. // 图片
  123. addIconImg(arr) {
  124. if (arr[0].imgUrl || this.defBg == 'diy') {
  125. this.form.imgUrl = arr[0].imgUrl
  126. this.defBg = arr[0].imgUrl ? 'diy':''
  127. }
  128. this.update()
  129. },
  130. bgChange(url) {
  131. this.defBg = url || '';
  132. this.form.imgUrl = this.defBg
  133. this.update()
  134. },
  135. // 内边距设置
  136. paddingChange(data) {
  137. console.log("paddingChange", data);
  138. this.sizeInfos = data;
  139. const [topInfo, bottomInfo, lrInfo] = this.sizeInfos;
  140. const formatValue = info => info ? `${info.value}${info.unit}` : '0px';
  141. const top = formatValue(topInfo);
  142. const bottom = formatValue(bottomInfo);
  143. const lr = formatValue(lrInfo);
  144. this.form = {
  145. ...this.form,
  146. paddingTop: top,
  147. paddingBottom: bottom,
  148. paddingLeft: lr,
  149. paddingRight: lr
  150. };
  151. this.update();
  152. },
  153. update() {
  154. this.$emit("change", this.form)
  155. },
  156. }
  157. });
  158. </script>
  159. <style lang="scss">
  160. .bg-img-box {
  161. display: flex;
  162. flex-wrap: wrap;
  163. background: #f6f6f6;
  164. padding:12px 9px 0;
  165. .bg-img-item {
  166. display: flex;
  167. flex-direction: column;
  168. text-align: center;
  169. margin-right: 12px;
  170. .img-text {
  171. color: #606266
  172. }
  173. }
  174. .bg-img {
  175. border:1px solid #e6e6e6;
  176. background: #fff;
  177. width:80px;
  178. height:60px;
  179. padding: 4px;
  180. border-radius:4px;
  181. }
  182. .active-img {
  183. border-color:var(--diy-color)
  184. }
  185. }
  186. </style>