diy-align.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template id="diy-align">
  2. <diy-style-contain :title="title">
  3. <div class="diy-align-content" flex="cross:center">
  4. <div class="diy-align-img"
  5. flex="cross:center main:center"
  6. v-for="(item, index) in imgAlign"
  7. :key="index"
  8. :class="imgIndex == item.type ? 'active' : ''"
  9. @click="toggle(item, index)"
  10. >
  11. <el-image class="img-left" :src="imgUrl + item.icon"></el-image>
  12. </div>
  13. </div>
  14. </diy-style-contain>
  15. </template>
  16. <script>
  17. /**
  18. * 文字位置组件
  19. */
  20. Vue.component('diy-align', {
  21. name: "diy-align",
  22. props: {
  23. title: { // 标题
  24. type: String,
  25. default: '文字位置'
  26. },
  27. aligns: { // 位置展示数组
  28. type: Array,
  29. default: () => {
  30. return ['left', 'center']
  31. }
  32. },
  33. current: { // 默认选中值
  34. type: String,
  35. default: 'left'
  36. }
  37. },
  38. template: '#diy-align',
  39. data() {
  40. return {
  41. imgUrl: 'resources/img/decorate/',
  42. imgAlign: [],
  43. imgIndex: 'left'
  44. }
  45. },
  46. watch: {
  47. aligns: {
  48. deep:true,
  49. immediate: true,
  50. handler(val) {
  51. // console.log(val)
  52. val.forEach(item => {
  53. // this.imgAlign[item] = 'align-' + item + '.png'
  54. this.imgAlign.push({
  55. icon: 'align-' + item + '.png',
  56. type: item
  57. })
  58. })
  59. }
  60. },
  61. current: {
  62. deep:true,
  63. immediate: true,
  64. handler(val) {
  65. this.imgIndex = val || 'left'
  66. }
  67. }
  68. },
  69. create() {
  70. },
  71. methods: {
  72. toggle(it, i) {
  73. this.imgIndex = it.type
  74. this.$emit('change', it.type)
  75. // var result = deepClone(this.activeItem)
  76. // console.log(result.computedStyle)
  77. // const style = {
  78. // 'align-items': it.type == 'left' ? 'flex-start' : it.type == 'center' ? 'center' : 'flex-end'
  79. // } // 数据内部维护
  80. // result.computedStyle.searchIpts = style
  81. // console.log(result.computedStyle)
  82. // this.$emit("update", result)
  83. },
  84. }
  85. });
  86. </script>
  87. <style>
  88. .diy-align-box {
  89. /* padding: 16px 20px;
  90. border-bottom: 10px solid #F4F6F8; */
  91. }
  92. .diy-align-content {
  93. padding-top: 20px;
  94. margin-right: 10px;
  95. }
  96. .diy-align-img {
  97. width: 50px;
  98. height: 50px;
  99. margin-right: 20px;
  100. }
  101. .diy-align-content .active {
  102. border-radius: 5px;
  103. border: 1px solid #707070;
  104. }
  105. .img-left {
  106. width: 30px;
  107. height: 35px
  108. }
  109. </style>