VciFormSelection.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <div
  3. :class="[{'vfs-active': visibleSelectOption, 'vfs-disabled': disabled}, `sl-${location}`]"
  4. class="VciFormSelection"
  5. @mouseleave="blur()"
  6. @mousemove="!disabled && focus()"
  7. >
  8. <div class="vfs-core vci-tc-alpha vci-flex-rml vci-size-100">
  9. <div class="sc-name vci-flex-fill vci-flex-rcm vci-to-e vci-ta-c">
  10. <span :title="name">{{ name }}</span>
  11. <span>{{ suffix }}</span>
  12. </div>
  13. <i class="sc-arrow vci-transition-quick vci-bg-contain vci-flex-0-0"></i>
  14. </div>
  15. <div class="vfs-options vci-left-0 vci-transition">
  16. <vci-scroll>
  17. <div
  18. v-for="(option, i) in options"
  19. :key="i"
  20. :class="{ 'so-selected': value === option.value }"
  21. class="vfs-option vci-flex-rml vci-tc-alpha"
  22. @pointerup="$emit('input', option.value)"
  23. >
  24. <i class="so-icon vci-bg-contain vci-transition-quick"></i>
  25. <span>{{ option.name }}</span>
  26. </div>
  27. </vci-scroll>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. // power by visual-ceiling, at 2024/12/21 16:25
  33. import { isEmpty } from "@vci/helper/src/other";
  34. import VciScroll from "../other/VciScroll.vue";
  35. export default {
  36. name: "VciFormSelection",
  37. components: { VciScroll },
  38. props: {
  39. value: {
  40. type: [Number, Boolean, String, Object, Date, Array],
  41. default: null
  42. },
  43. options: {
  44. type: Array,
  45. default: () => ([])
  46. },
  47. // placeholder
  48. placeholder: {
  49. type: String,
  50. default: "- 请选择 -"
  51. },
  52. // 选项列表位置 bottom|top
  53. location: {
  54. type: String,
  55. default: "bottom"
  56. },
  57. // 选中项后缀
  58. suffix: {
  59. type: [String, Number],
  60. default: ""
  61. },
  62. // 是否禁用
  63. disabled: {
  64. type: Boolean,
  65. default: false
  66. }
  67. },
  68. data() {
  69. return {
  70. visibleSelectOption: false
  71. };
  72. },
  73. computed: {
  74. name() {
  75. const target = this.options.find(option => option.value === this.value);
  76. if(target) return target.name;
  77. else return isEmpty(this.value) ? this.placeholder : this.value;
  78. }
  79. },
  80. methods: {
  81. focus() {
  82. clearTimeout(this.inter);
  83. this.visibleSelectOption = true;
  84. },
  85. blur(force = false) {
  86. clearTimeout(this.inter);
  87. if(force) this.visibleSelectOption = false;
  88. else this.inter = setTimeout(() => this.visibleSelectOption = false, .2e3);
  89. }
  90. }
  91. };
  92. </script>
  93. <style lang="scss" scoped>
  94. .VciFormSelection {
  95. position: relative;
  96. .vfs-core {
  97. position: relative;
  98. z-index: 2;
  99. border-radius: 4px;
  100. border: 1px solid #fff;
  101. padding: 2px 12px;
  102. .sc-arrow {
  103. width: 12px;
  104. height: 8px;
  105. margin-left: 4px;
  106. margin-right: 4px;
  107. background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAICAMAAAD6Ou7DAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABCUExURQAAAP///////////////////////////////////////////////////////////////////////////////////whf0oYAAAAVdFJOUwDHC+XQHgz5+onBtsLn2wfWAczS7NZ4/TsAAAA4SURBVAjXY2BAAbwc7BDAIcLAwCMKA8JAKW4oWwiskAvMFhCEaGMEsvn4YYawiDIzwU1k42QFUQCsyQMSSkAT1AAAAABJRU5ErkJggg==");
  108. }
  109. }
  110. .vfs-options {
  111. z-index: 1;
  112. width: 100%;
  113. height: 300%;
  114. border-radius: 4px;
  115. border: 1px solid #818a8c;
  116. opacity: 0;
  117. backdrop-filter: blur(10px);
  118. pointer-events: none;
  119. transform: translateY(-10%);
  120. transform-origin: 50% 0;
  121. box-shadow: 0 0 12px #000;
  122. padding: 4px 6px 4px 0;
  123. .vfs-option {
  124. min-height: 26px;
  125. .so-icon {
  126. width: 20px;
  127. height: 26px;
  128. opacity: 0;
  129. background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAaCAMAAACAXYxPAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAADSUExURf///////////////////////////wAAAP///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////3HO0J4AAABFdFJOUwEGDAkEBQcAAwIIEAoLDw0REg4YHBQTFiUbHhUdGh8uLxcyQEEZqSIrMCw8QzU3OCeaJDZbTC1jRTvwkIh1Vtzhu0nuZEvFSoEAAAFDSURBVCjPXZJVbsUwFERNccxhfMxlZibvf0t1nDxV6nwe+dKMQdgJdApBOAh4wgcB8Ac5G8SBx6BnhAROhHTcQ85IAIXAglIYeNo1ZIFQKIoQUpgGxPcAnhlZGmmQokEHQ06oimRRtlexlBGGhPcPdVzkxDzORlJq4esZxGm52Nw35mE5Qe5pD5WsGv783iSr67Gb1dUzquNNGzL7/aVn5y1lDro5KKnan/zV2pf1xXyK9jDOn9521tqb7GjeOAs4czCb3oGt/bjNT2eZX9T1lNmY1PZzlx0vK2dBP92MJsHlNqzXhyOl/PZuzyippitSnxwUUdrvyd1FsliIyVkdx0ZTwvztECNTJvnYxAYNt7vjqUKplKlMNR5c8n5ijZDWWEDnp0/QpRFASoWgsLfYB+czIvuIwL809xmD4Sf40MGQ+y+EyxoHtWXdXQAAAABJRU5ErkJggg==");
  130. }
  131. span {
  132. color: #fff;
  133. opacity: .8;
  134. transition: .2s ease-in-out;
  135. }
  136. &.so-selected {
  137. .so-icon {
  138. opacity: 1;
  139. }
  140. span {
  141. color: #7bb2ff;
  142. opacity: 1;
  143. }
  144. }
  145. }
  146. }
  147. &.sl-bottom {
  148. .vfs-options {
  149. top: calc(100% + 4px);
  150. transform: translateY(-10%);
  151. }
  152. }
  153. &.sl-top {
  154. .vfs-options {
  155. bottom: calc(100% + 4px);
  156. transform: translateY(10%);
  157. }
  158. }
  159. &.vfs-active {
  160. .vfs-options {
  161. opacity: 1;
  162. backdrop-filter: blur(8px);
  163. pointer-events: auto;
  164. transform: scale(1) translateY(0);
  165. }
  166. }
  167. &.vfs-disabled {
  168. cursor: not-allowed;
  169. .vfs-core {
  170. border-color: #333;
  171. opacity: .6;
  172. cursor: not-allowed;
  173. }
  174. }
  175. }
  176. </style>