|
|
@@ -21,12 +21,14 @@ const cascadeRef = ref();
|
|
|
const props = defineProps({
|
|
|
modelValue: [String, Array],
|
|
|
zlevel: propTypes.number.def(3),
|
|
|
- multiple: propTypes.bool.def(false)
|
|
|
+ multiple: propTypes.bool.def(false),
|
|
|
+ checkStrictly: propTypes.bool.def(false)
|
|
|
});
|
|
|
const value = ref();
|
|
|
const propsJson: CascaderProps = {
|
|
|
lazy: true,
|
|
|
multiple: props.multiple,
|
|
|
+ checkStrictly: props.checkStrictly,
|
|
|
lazyLoad(node, resolve) {
|
|
|
console.log(node);
|
|
|
const { level, value } = node;
|
|
|
@@ -50,24 +52,42 @@ const propsJson: CascaderProps = {
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
+// 传入code判断该code在那一级
|
|
|
+const getLevel = (code: string) => {
|
|
|
+ // 去掉code末尾后面的00,再根据长度判断是那一级
|
|
|
+ const trimmedCode = code.replace(/00+$/, '');
|
|
|
+ const length = trimmedCode.length;
|
|
|
+ if (length === 2) {
|
|
|
+ return 1; // 省级
|
|
|
+ } else if (length === 4) {
|
|
|
+ return 2; // 市级
|
|
|
+ } else if (length === 6) {
|
|
|
+ return 3; // 区县级
|
|
|
+ } else if (length === 9) {
|
|
|
+ return 4; // 镇级
|
|
|
+ }
|
|
|
+ return 0; // 未知级别
|
|
|
+};
|
|
|
watch(
|
|
|
() => props.modelValue,
|
|
|
- (val) => {
|
|
|
+ (val: any) => {
|
|
|
if (val) {
|
|
|
if (!props.multiple) {
|
|
|
const c8 = val.slice(0, 9);
|
|
|
const c6 = val.slice(0, 6);
|
|
|
const c4 = val.slice(0, 4);
|
|
|
const c2 = val.slice(0, 2);
|
|
|
- if (props.zlevel === 3) {
|
|
|
- value.value = [c2 + '0000', c4 + '00000000', c6 + '000000', val];
|
|
|
+ if (getLevel(val) === 1) {
|
|
|
+ value.value = [c2 + '0000'];
|
|
|
}
|
|
|
- if (props.zlevel === 4) {
|
|
|
- value.value = [c2 + '0000', c4 + '00000000', c6 + '000000', c8 + '000', val];
|
|
|
+ if (getLevel(val) === 2) {
|
|
|
+ value.value = [c2 + '0000', c4 + '00000000'];
|
|
|
}
|
|
|
- if (props.zlevel === 2) {
|
|
|
+ if (getLevel(val) === 3) {
|
|
|
value.value = [c2 + '0000', c4 + '00000000', c6 + '000000'];
|
|
|
- console.log(value.value);
|
|
|
+ }
|
|
|
+ if (getLevel(val) === 4) {
|
|
|
+ value.value = [c2 + '0000', c4 + '00000000', c6 + '000000', c8 + '000'];
|
|
|
}
|
|
|
} else {
|
|
|
if (Array.isArray(val)) {
|
|
|
@@ -97,7 +117,6 @@ const change = (event: any) => {
|
|
|
address.push(e.pathLabels.join(''));
|
|
|
});
|
|
|
emit('update:modelValue', vl);
|
|
|
- console.log(address.toString());
|
|
|
emit('change', { value, vl, name: address.toString() });
|
|
|
} else {
|
|
|
emit('update:modelValue', null);
|