| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- const n = `<template>
- <div class="s-color-picker-common">
- <a-popover trigger="click" placement="bottomLeft" v-model:open="visible">
- <template #content>
- <div class="picker-panel">
- <div class="palette">
- <span
- class="swatch"
- v-for="c in palette"
- :key="c"
- :style="{ backgroundColor: c }"
- :class="{ active: c.toLowerCase() === normalized }"
- @click="pick(c)"
- />
- </div>
- <div class="native-row">
- <input type="color" class="native-color" :value="normalized" @input="onNative" />
- <span class="native-tip">{{ $l('自定义颜色') }}</span>
- </div>
- </div>
- </template>
- <a-input
- class="color-input"
- :value="value"
- :style="{ width: width + 'px' }"
- placeholder=""
- @update:value="onInput"
- >
- <template #prefix>
- <span class="color-block" :style="[{ backgroundColor: normalized }, blockStyle]" />
- </template>
- </a-input>
- </a-popover>
- </div>
- </template>
- <script setup>
- import { computed, ref } from 'vue'
- const props = defineProps({
- // 颜色值(hex),支持 v-model:value
- value: {
- type: String,
- default: ''
- },
- // 色块宽度,单位 px
- width: {
- type: Number,
- default: 40
- },
- // 透传给色块的样式
- blockStyle: {
- type: Object,
- default() {
- return {}
- }
- }
- })
- const emits = defineEmits(['update:value', 'change'])
- const visible = ref(false)
- const palette = [
- '#1677ff',
- '#1167ff',
- '#722ed1',
- '#eb2f96',
- '#f5222d',
- '#fa541c',
- '#fa8c16',
- '#faad14',
- '#13c2c2',
- '#52c41a',
- '#1afa29',
- '#44d7b6'
- ]
- const normalized = computed(() =>
- /^#([0-9a-fA-F]{6})$/.test(props.value) ? props.value.toLowerCase() : '#1677ff'
- )
- const emitValue = (val) => {
- emits('update:value', val)
- emits('change', val)
- }
- const pick = (c) => {
- emitValue(c)
- visible.value = false
- }
- const onNative = (e) => {
- emitValue(e.target.value)
- }
- const onInput = (val) => {
- emitValue(val)
- }
- <\/script>
- <style lang="less" scoped>
- .s-color-picker-common {
- margin-left: 10px;
- display: inline-block;
- }
- .color-block {
- display: inline-block;
- width: 16px;
- height: 16px;
- border-radius: 3px;
- border: 1px solid var(--s-border-color-base);
- box-sizing: border-box;
- cursor: pointer;
- }
- .picker-panel {
- width: 220px;
- .palette {
- display: flex;
- flex-wrap: wrap;
- justify-content: flex-start;
- gap: 8px;
- }
- .swatch {
- width: 24px;
- height: 24px;
- border-radius: 4px;
- cursor: pointer;
- border: 1px solid transparent;
- box-sizing: border-box;
- }
- .swatch.active {
- border-color: var(--s-text-color);
- }
- .native-row {
- display: flex;
- align-items: center;
- margin-top: 12px;
- padding-top: 12px;
- border-top: 1px solid var(--s-border-color-split);
- .native-color {
- width: 32px;
- height: 28px;
- padding: 0;
- border: 1px solid var(--s-border-color-base);
- border-radius: 4px;
- background: none;
- cursor: pointer;
- }
- .native-tip {
- margin-left: 8px;
- color: var(--s-text-color-secondary);
- font-size: 13px;
- }
- }
- }
- .color-input {
- :deep(.ant-input-prefix) {
- margin-inline-end: 2px;
- }
- :deep(input.ant-input) {
- padding-left: 2px;
- padding-right: 2px;
- }
- }
- </style>
- `;
- export {
- n as default
- };
|