UNPKG

@wfrog/vc

Version:

vue3 组件库 vc

186 lines (179 loc) 7.22 kB
import './index.css' import '../../chunk/E_WRn0OP.mjs'; import '../../chunk/Bm4zCpG6.mjs'; import { E as ElSelect, a as ElOption } from '../../chunk/DVg9glNI.mjs'; import '../../chunk/CJQcPuNK.mjs'; import '../../chunk/DUd8IaU9.mjs'; import { defineComponent, computed, ref, onBeforeMount, createBlock, openBlock, mergeProps, unref, isRef, createSlots, withCtx, createElementBlock, normalizeStyle, Fragment, renderList, createCommentVNode, createTextVNode, normalizeClass, toDisplayString } from 'vue'; import { _ as _sfc_main$1 } from '../flag/flag.mjs'; import { C as Component$1 } from '../thousand-input/thousand-input.mjs'; import { u as useVModel } from '../../chunk/eQT9aAiW.mjs'; import { _ as _export_sfc } from '../../chunk/pcqpp-6-.mjs'; const data = [ { code: "CNY", flag: "CHN", option: { prefix: "¥", decimalScale: 2, integerScale: 20 } }, { code: "USD", flag: "USA", option: { prefix: "$", decimalScale: 2, integerScale: 20 } }, { code: "JPY", flag: "JPN", option: { prefix: "¥", decimalScale: 0, integerScale: 20 } }, { code: "EUR", flag: "EU", option: { prefix: "€", decimalScale: 2, integerScale: 20 } }, { code: "TWD", flag: "CHN", option: { prefix: "NT$", decimalScale: 0, integerScale: 20 } }, { code: "KRW", flag: "KOR", option: { prefix: "₩", decimalScale: 0, integerScale: 20 } } ]; const _hoisted_1 = { key: 0 }; const _hoisted_2 = { key: 1 }; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "currency", props: { modelValue: {}, code: {}, flag: { type: Boolean, default: false }, prefix: { type: Boolean, default: true }, prepend: { type: Boolean, default: true }, append: { type: Boolean, default: false } }, emits: ["update:modelValue", "change"], setup(__props, { emit: __emit }) { const props = __props; const emits = __emit; const myValue = useVModel(props, "modelValue", emits); const selectStyle = computed(() => ({ width: props.flag ? "7.5em" : "6em" })); const formatValue = ref(""); const myCode = ref(); const myCurrencyInfo = computed(() => data.find((item) => item.code === myCode.value)); const thousandOption = computed(() => ({ ...myCurrencyInfo.value?.option, prefix: props.prefix ? myCurrencyInfo.value?.option.prefix : "", elInputIndex: Array.isArray(props.code) ? 1 : 0 })); const currencyInfo = computed(() => { if (Array.isArray(props.code)) { return data.filter((item) => props.code.includes(item.code)); } return data.find((item) => item.code === props.code); }); function handleChange(val) { emits("change", [...val, myCode.value]); } function handleCodeChange() { handleChange([myValue.value, formatValue.value]); } onBeforeMount(() => { if (Array.isArray(currencyInfo.value) && currencyInfo.value.length > 0) { myCode.value = currencyInfo.value[0].code; } else if (!Array.isArray(currencyInfo.value)) { myCode.value = currencyInfo.value?.code; } }); return (_ctx, _cache) => { const _component_ElOption = ElOption; const _component_ElSelect = ElSelect; return openBlock(), createBlock(Component$1, mergeProps({ modelValue: unref(myValue), "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(myValue) ? myValue.value = $event : null), "format-value": unref(formatValue), "onUpdate:formatValue": _cache[2] || (_cache[2] = ($event) => isRef(formatValue) ? formatValue.value = $event : null), options: unref(thousandOption) }, _ctx.$attrs, { class: { [_ctx.$style.append]: __props.append, [_ctx.$style.prepend]: __props.prepend }, onChange: handleChange }), createSlots({ _: 2 }, [ __props.prepend ? { name: "prepend", fn: withCtx(() => [ Array.isArray(unref(currencyInfo)) ? (openBlock(), createBlock(_component_ElSelect, { key: 0, modelValue: unref(myCode), "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(myCode) ? myCode.value = $event : null), style: normalizeStyle(unref(selectStyle)), onChange: handleCodeChange }, createSlots({ default: withCtx(() => [ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(currencyInfo), (item) => { return openBlock(), createBlock(_component_ElOption, { key: item.code, value: item.code }, { default: withCtx(() => [ __props.flag ? (openBlock(), createBlock(_sfc_main$1, { key: 0, code: item.flag, class: normalizeClass(_ctx.$style.flag) }, null, 8, ["code", "class"])) : createCommentVNode("", true), createTextVNode(toDisplayString(item.code), 1) ]), _: 2 }, 1032, ["value"]); }), 128)) ]), _: 2 }, [ __props.flag ? { name: "prefix", fn: withCtx(() => [ unref(myCurrencyInfo) ? (openBlock(), createBlock(_sfc_main$1, { key: 0, code: unref(myCurrencyInfo)?.flag }, null, 8, ["code"])) : createCommentVNode("", true) ]), key: "0" } : void 0 ]), 1032, ["modelValue", "style"])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [ __props.flag ? (openBlock(), createBlock(_sfc_main$1, { key: 0, code: unref(currencyInfo).flag, class: normalizeClass(_ctx.$style.flag) }, null, 8, ["code", "class"])) : createCommentVNode("", true), createTextVNode(toDisplayString(unref(currencyInfo).code), 1) ], 64)) ]), key: "0" } : void 0, __props.append ? { name: "append", fn: withCtx(() => [ Array.isArray(unref(currencyInfo)) ? (openBlock(), createElementBlock("span", _hoisted_1, toDisplayString(unref(myCurrencyInfo).code), 1)) : (openBlock(), createElementBlock("span", _hoisted_2, toDisplayString(unref(currencyInfo).code), 1)) ]), key: "1" } : void 0 ]), 1040, ["modelValue", "format-value", "options", "class"]); }; } }); /* unplugin-vue-components disabled */const append = "_append_vkceh_1"; const flag = "_flag_vkceh_6"; const style0 = { append: append, "el-input__wrapper": "_el-input__wrapper_vkceh_1", flag: flag }; const cssModules = { "$style": style0 }; const Component = /* @__PURE__ */ _export_sfc(_sfc_main, [["__cssModules", cssModules]]); const __vite_glob_0_8 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({ __proto__: null, default: Component }, Symbol.toStringTag, { value: 'Module' })); export { Component as C, __vite_glob_0_8 as _ };