pulldownMenuInEditor.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div class="pull-down-menu-in-editor" v-clickoutside="onClickOutside">
  3. <button class="menu-cover" @click="isExpand = !isExpand">
  4. {{ placeholder ? placeholder : current.label }}
  5. <i
  6. class="iconfont icon-material_preview_upload_collect"
  7. :class="{ flip: isExpand }"
  8. ></i>
  9. </button>
  10. <div class="menu" v-show="isExpand">
  11. <button
  12. v-for="(item, index) of valueList"
  13. :key="index"
  14. @click="onSelect(item)"
  15. >
  16. <!-- {{ $i18n.t(`zh_key.${item}`) }} -->
  17. {{ item.label }}
  18. </button>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. props: {
  25. valueList: {
  26. type: Array,
  27. default: function () {
  28. return [];
  29. },
  30. },
  31. placeholder: {
  32. type: String,
  33. default: "",
  34. },
  35. value: {
  36. type: String,
  37. required: true,
  38. },
  39. },
  40. data() {
  41. return {
  42. isExpand: false,
  43. current: {
  44. id: "",
  45. label: "",
  46. },
  47. };
  48. },
  49. watch: {
  50. valueList: {
  51. handler(val) {
  52. if (val && val.length > 0) {
  53. if (!this.current.id) {
  54. this.current = this.valueList[0];
  55. }
  56. }
  57. },
  58. immediate: true,
  59. },
  60. value: {
  61. handler(val) {
  62. const changeValue = this.valueList.find((i) => i.id === val);
  63. if (changeValue) {
  64. this.current = changeValue;
  65. }
  66. },
  67. immediate: true,
  68. },
  69. },
  70. methods: {
  71. onClickOutside() {
  72. if (this.isExpand) {
  73. this.isExpand = false;
  74. }
  75. },
  76. onSelect(item) {
  77. console.log(item, "ads");
  78. this.isExpand = false;
  79. this.$emit("input", item.id);
  80. },
  81. },
  82. };
  83. </script>
  84. <style lang="less" scoped>
  85. button {
  86. background: #252526;
  87. border: 1px solid #404040;
  88. height: 36px;
  89. color: #fff;
  90. width: 100%;
  91. }
  92. .pull-down-menu-in-editor {
  93. width: 140px;
  94. position: relative;
  95. min-width: 160px;
  96. > button.menu-cover {
  97. display: flex;
  98. justify-content: space-between;
  99. align-items: center;
  100. padding: 16px;
  101. cursor: pointer;
  102. > .icon-material_preview_upload_collect {
  103. font-size: 11px;
  104. color: rgba(255, 255, 255, 0.6);
  105. border-radius: 2px;
  106. &.flip {
  107. transform: translateY(-2px) rotate(180deg);
  108. }
  109. }
  110. }
  111. > .menu {
  112. position: absolute;
  113. width: 100%;
  114. > button {
  115. display: block;
  116. border-top: none;
  117. cursor: pointer;
  118. text-align: left;
  119. padding: 0 16px;
  120. }
  121. }
  122. }
  123. </style>