feat: add PcaCascader

This commit is contained in:
chansee97 2024-05-12 13:27:23 +08:00
parent 922e82d12f
commit 8bafc3aa36
6 changed files with 115 additions and 10 deletions

View File

@ -5,7 +5,9 @@
"close": "Closure", "close": "Closure",
"reload": "Refresh", "reload": "Refresh",
"choose": "Choose", "choose": "Choose",
"navigate": "Navigate" "navigate": "Navigate",
"inputPlaceholder": "please enter",
"selectPlaceholder": "please choose"
}, },
"app": { "app": {
"loginOut": "Login out", "loginOut": "Login out",
@ -121,7 +123,8 @@
"permissionDemo": "Permissions example", "permissionDemo": "Permissions example",
"setting": "System settings", "setting": "System settings",
"userCenter": "Personal Center", "userCenter": "Personal Center",
"accountSetting": "User settings" "accountSetting": "User settings",
"cascader": "Administrative region selection"
}, },
"http": { "http": {
"400": "Syntax error in the request", "400": "Syntax error in the request",

View File

@ -5,7 +5,9 @@
"reload": "刷新", "reload": "刷新",
"close": "关闭", "close": "关闭",
"choose": "选择", "choose": "选择",
"navigate": "切换" "navigate": "切换",
"inputPlaceholder": "请输入",
"selectPlaceholder": "请选择"
}, },
"app": { "app": {
"loginOut": "退出登录", "loginOut": "退出登录",
@ -144,6 +146,7 @@
"dictionarySetting": "字典设置", "dictionarySetting": "字典设置",
"menuSetting": "菜单设置", "menuSetting": "菜单设置",
"userCenter": "个人中心", "userCenter": "个人中心",
"about": "关于" "about": "关于",
"cascader": "省市区联动"
} }
} }

View File

@ -83,7 +83,7 @@ watch(editorModel, (newValue, oldValue) => {
model.value = newValue model.value = newValue
else if (!newValue) else if (!newValue)
quillInstance!.setContents([]) editorInst!.setContents([])
}) })
watch( watch(
@ -93,11 +93,9 @@ watch(
}, },
) )
onBeforeUnmount(() => quillInstance = null) onBeforeUnmount(() => editorInst = null)
</script> </script>
<template> <template>
<div class="h-2xl"> <div ref="editorRef" />
<div ref="editorRef" />
</div>
</template> </template>

View File

@ -0,0 +1,27 @@
<script setup lang="ts">
import type { CascaderOption } from 'naive-ui'
defineOptions({
name: 'PcaCascader',
})
// https://github.com/modood/Administrative-divisions-of-China
const pcaCode = shallowRef<CascaderOption[]>()
async function fetchPcaCode() {
return await fetch('https://cdn.jsdelivr.net/gh/modood/Administrative-divisions-of-China/dist/pca-code.json').then(res => res.json())
}
onMounted(async () => {
pcaCode.value = await fetchPcaCode()
})
</script>
<template>
<n-cascader
:options="pcaCode"
value-field="code"
label-field="name"
check-strategy="all"
filterable
clearable
/>
</template>

View File

@ -0,0 +1,72 @@
<script setup lang="ts">
const value = ref()
const cbValue = ref()
const cbOption = ref()
const cbPathValues = ref()
function handleUpdateValue(value: string, option: any, pathValues: any[]) {
cbValue.value = value
cbOption.value = { code: option.code, name: option.name }
cbPathValues.value = pathValues.map(i => ({ code: i.code, name: i.name }))
}
const formRef = ref()
const formValue = ref({
region: null,
})
function handleValidateClick() {
formRef.value?.validate((errors: any) => {
if (!errors)
window.$message.success('Valid')
else
window.$message.error('Invalid')
})
}
</script>
<template>
<n-card title="省市区联动">
<n-h2>当前选择行政区{{ value }}</n-h2>
<PcaCascader v-model:value="value" @update:value="handleUpdateValue" />
<div>
<n-h2>回调value</n-h2>
<pre class="bg-#eee">
{{ cbValue }}
</pre>
</div>
<div>
<n-h2>回调option</n-h2>
<pre class="bg-#eee">
{{ cbOption }}
</pre>
</div>
<div>
<n-h2>回调pathValues</n-h2>
<pre class="bg-#eee">
{{ cbPathValues }}
</pre>
</div>
<n-h2>表单验证</n-h2>
<n-form
ref="formRef"
inline
:label-width="80"
:model="formValue"
>
<n-form-item label="地区" path="region" :rule="[{ required: true, message: '地区必填' }]">
<PcaCascader v-model:value="formValue.region" />
</n-form-item>
<n-form-item>
<n-button attr-type="button" @click="handleValidateClick">
验证
</n-button>
</n-form-item>
</n-form>
</n-card>
</template>
<style scoped></style>

View File

@ -13,7 +13,9 @@ onMounted(() => {
<n-space vertical :size="12"> <n-space vertical :size="12">
<n-alert title="基于 Quill 封装" type="success" /> <n-alert title="基于 Quill 封装" type="success" />
<n-space :size="12"> <n-space :size="12">
<RichTextEditor v-model="text" /> <div class="h-2xl">
<RichTextEditor v-model="text" />
</div>
<div> <div>
<n-h2>v-html 预览</n-h2> <n-h2>v-html 预览</n-h2>
<div v-html="text" /> <div v-html="text" />