| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <template>
- <div
- :class="[{'vfs-active': visibleSelectOption, 'vfs-disabled': disabled}, `sl-${location}`]"
- class="VciFormSelection"
- @mouseleave="blur()"
- @mousemove="!disabled && focus()"
- >
- <div class="vfs-core vci-tc-alpha vci-flex-rml vci-size-100">
- <div class="sc-name vci-flex-fill vci-flex-rcm vci-to-e vci-ta-c">
- <span :title="name">{{ name }}</span>
- <span>{{ suffix }}</span>
- </div>
- <i class="sc-arrow vci-transition-quick vci-bg-contain vci-flex-0-0"></i>
- </div>
- <div class="vfs-options vci-left-0 vci-transition">
- <vci-scroll>
- <div
- v-for="(option, i) in options"
- :key="i"
- :class="{ 'so-selected': value === option.value }"
- class="vfs-option vci-flex-rml vci-tc-alpha"
- @pointerup="$emit('input', option.value)"
- >
- <i class="so-icon vci-bg-contain vci-transition-quick"></i>
- <span>{{ option.name }}</span>
- </div>
- </vci-scroll>
- </div>
- </div>
- </template>
- <script>
- // power by visual-ceiling, at 2024/12/21 16:25
- import { isEmpty } from "@vci/helper/src/other";
- import VciScroll from "../other/VciScroll.vue";
- export default {
- name: "VciFormSelection",
- components: { VciScroll },
- props: {
- value: {
- type: [Number, Boolean, String, Object, Date, Array],
- default: null
- },
- options: {
- type: Array,
- default: () => ([])
- },
- // placeholder
- placeholder: {
- type: String,
- default: "- 请选择 -"
- },
- // 选项列表位置 bottom|top
- location: {
- type: String,
- default: "bottom"
- },
- // 选中项后缀
- suffix: {
- type: [String, Number],
- default: ""
- },
- // 是否禁用
- disabled: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- visibleSelectOption: false
- };
- },
- computed: {
- name() {
- const target = this.options.find(option => option.value === this.value);
- if(target) return target.name;
- else return isEmpty(this.value) ? this.placeholder : this.value;
- }
- },
- methods: {
- focus() {
- clearTimeout(this.inter);
- this.visibleSelectOption = true;
- },
- blur(force = false) {
- clearTimeout(this.inter);
- if(force) this.visibleSelectOption = false;
- else this.inter = setTimeout(() => this.visibleSelectOption = false, .2e3);
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .VciFormSelection {
- position: relative;
- .vfs-core {
- position: relative;
- z-index: 2;
- border-radius: 4px;
- border: 1px solid #fff;
- padding: 2px 12px;
- .sc-arrow {
- width: 12px;
- height: 8px;
- margin-left: 4px;
- margin-right: 4px;
- background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAICAMAAAD6Ou7DAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABCUExURQAAAP///////////////////////////////////////////////////////////////////////////////////whf0oYAAAAVdFJOUwDHC+XQHgz5+onBtsLn2wfWAczS7NZ4/TsAAAA4SURBVAjXY2BAAbwc7BDAIcLAwCMKA8JAKW4oWwiskAvMFhCEaGMEsvn4YYawiDIzwU1k42QFUQCsyQMSSkAT1AAAAABJRU5ErkJggg==");
- }
- }
- .vfs-options {
- z-index: 1;
- width: 100%;
- height: 300%;
- border-radius: 4px;
- border: 1px solid #818a8c;
- opacity: 0;
- backdrop-filter: blur(10px);
- pointer-events: none;
- transform: translateY(-10%);
- transform-origin: 50% 0;
- box-shadow: 0 0 12px #000;
- padding: 4px 6px 4px 0;
- .vfs-option {
- min-height: 26px;
- .so-icon {
- width: 20px;
- height: 26px;
- opacity: 0;
- background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAaCAMAAACAXYxPAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAADSUExURf///////////////////////////wAAAP///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////3HO0J4AAABFdFJOUwEGDAkEBQcAAwIIEAoLDw0REg4YHBQTFiUbHhUdGh8uLxcyQEEZqSIrMCw8QzU3OCeaJDZbTC1jRTvwkIh1Vtzhu0nuZEvFSoEAAAFDSURBVCjPXZJVbsUwFERNccxhfMxlZibvf0t1nDxV6nwe+dKMQdgJdApBOAh4wgcB8Ac5G8SBx6BnhAROhHTcQ85IAIXAglIYeNo1ZIFQKIoQUpgGxPcAnhlZGmmQokEHQ06oimRRtlexlBGGhPcPdVzkxDzORlJq4esZxGm52Nw35mE5Qe5pD5WsGv783iSr67Gb1dUzquNNGzL7/aVn5y1lDro5KKnan/zV2pf1xXyK9jDOn9521tqb7GjeOAs4czCb3oGt/bjNT2eZX9T1lNmY1PZzlx0vK2dBP92MJsHlNqzXhyOl/PZuzyippitSnxwUUdrvyd1FsliIyVkdx0ZTwvztECNTJvnYxAYNt7vjqUKplKlMNR5c8n5ijZDWWEDnp0/QpRFASoWgsLfYB+czIvuIwL809xmD4Sf40MGQ+y+EyxoHtWXdXQAAAABJRU5ErkJggg==");
- }
- span {
- color: #fff;
- opacity: .8;
- transition: .2s ease-in-out;
- }
- &.so-selected {
- .so-icon {
- opacity: 1;
- }
- span {
- color: #7bb2ff;
- opacity: 1;
- }
- }
- }
- }
- &.sl-bottom {
- .vfs-options {
- top: calc(100% + 4px);
- transform: translateY(-10%);
- }
- }
- &.sl-top {
- .vfs-options {
- bottom: calc(100% + 4px);
- transform: translateY(10%);
- }
- }
- &.vfs-active {
- .vfs-options {
- opacity: 1;
- backdrop-filter: blur(8px);
- pointer-events: auto;
- transform: scale(1) translateY(0);
- }
- }
- &.vfs-disabled {
- cursor: not-allowed;
- .vfs-core {
- border-color: #333;
- opacity: .6;
- cursor: not-allowed;
- }
- }
- }
- </style>
|