diy-style.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!-- 风格组件 -->
  2. <template id="diy-style">
  3. <diy-style-contain class="diy-style" :title="topName">
  4. <div class="diy-style-exhibit" flex="main:center cross:center">
  5. <el-image class="exhibit-img" :style="{...imgStyle}" :src="imgUrl + imgInfo[selIndex].img" fit="fill"></el-image>
  6. <div class="diy-update-style" @click="stylePop = true">
  7. 修改风格
  8. </div>
  9. </div>
  10. <el-dialog :title="topName" :visible.sync="stylePop" width="66%" :modal-append-to-body="false">
  11. <div flex="wrap:wrap" class="diy-style-info">
  12. <div :style="{width: (100/count) + '%'}" v-for="(item,index) in imgInfo" :key="index">
  13. <div class="diy-style-img" :class="{'diy-style-sel-img': index==selIndex}">
  14. <el-image :style="{'height': imgStyle.height}" style="width: 100%;" @click="selStyleImg(index)" :src="imgUrl + item.img" fit="fill"></el-image>
  15. <i v-show="index==selIndex" class="el-icon-success diy-style-icon"></i>
  16. </div>
  17. <div class="diy-style-text">{{item.text}}</div>
  18. <div class="diy-style-text" v-if="item.desc">{{item.desc}}</div>
  19. </div>
  20. </div>
  21. <div class="diy-style-bottom">
  22. <el-button size="mini" @click="stylePop = false" plain>取消</el-button>
  23. <el-button size="mini" @click="saveStyle" type="primary">确定</el-button>
  24. </div>
  25. </el-dialog>
  26. </diy-style-contain>
  27. </template>
  28. <script>
  29. Vue.component('diy-style', {
  30. template: '#diy-style',
  31. name: 'diy-style',
  32. props: {
  33. topName: { //头部标题
  34. type: String,
  35. default: "选择风格",
  36. },
  37. imgStyle: { //图片样式
  38. type: Object,
  39. default: () => {
  40. return {
  41. width: '206px',
  42. height: 'auto'
  43. }
  44. }
  45. },
  46. count: { //每格多少个
  47. type: [String, Number],
  48. default: 4,
  49. },
  50. imgUrl: { //图片路径开头
  51. type: String,
  52. default: "resources/img/decorate/"
  53. },
  54. defIndex: {
  55. type: Number,
  56. default: 0
  57. },
  58. /*
  59. 数据结构
  60. {
  61. img: "", //图片路径
  62. text: "", //展示文本
  63. }
  64. */
  65. imgInfo: {
  66. type: Array,
  67. default: () => {
  68. return []
  69. }
  70. }
  71. },
  72. data() {
  73. return {
  74. stylePop: false,
  75. selIndex: 0,
  76. }
  77. },
  78. created() {
  79. this.selIndex = this.defIndex;
  80. },
  81. methods: {
  82. selStyleImg(index) {
  83. this.selIndex = index;
  84. },
  85. saveStyle() {
  86. const item = this.imgInfo[this.selIndex]
  87. this.$emit("chang", this.selIndex, item);
  88. this.stylePop = false;
  89. }
  90. }
  91. })
  92. </script>
  93. <style>
  94. .diy-style-exhibit {
  95. background: #F4F3F7;
  96. height: 184px;
  97. position: relative;
  98. }
  99. .diy-update-style {
  100. position: absolute;
  101. bottom: 0;
  102. left: 0;
  103. width: 100%;
  104. height: 35px;
  105. line-height: 35px;
  106. text-align: center;
  107. background: rgba(102, 102, 102, 0.72);
  108. font-weight: bold;
  109. font-size: 14px;
  110. color: rgba(255, 255, 255, 0.82);
  111. }
  112. .diy-update-style,
  113. .diy-style-img:hover {
  114. cursor: pointer
  115. }
  116. .diy-style .el-dialog__header {
  117. border-bottom: 1px solid #f2f2f2;
  118. padding: 12px 22px;
  119. }
  120. .diy-style .el-dialog__body {
  121. padding: 0;
  122. }
  123. .diy-style .diy-style-bottom {
  124. border-top: 1px solid #f2f2f2;
  125. padding: 10px 20px;
  126. text-align: end;
  127. }
  128. .diy-style-info {
  129. padding: 16px;
  130. }
  131. .diy-style-img {
  132. background: #f7f8fa;
  133. border: 1px solid #ededed;
  134. width: 95%;
  135. position: relative;
  136. font-size: 0;
  137. }
  138. .diy-style-sel-img {
  139. border: 1px solid #3892F1;
  140. }
  141. .diy-style-icon {
  142. position: absolute;
  143. font-size: 16px;
  144. bottom: -8px;
  145. right: -8px;
  146. background: #FFF;
  147. border-radius: 50%;
  148. color: #2D8CF0;
  149. }
  150. .diy-style-text {
  151. width: 95%;
  152. text-align: center;
  153. margin-bottom: 10px;
  154. margin-top: 10px;
  155. }
  156. </style>