chore(config): 添加项目配置文件和隐私协议
- 添加 .editorconfig 文件统一代码风格 - 添加 .env.development 和 .env.example 环境配置文件 - 添加 .eslintignore 和 .eslintrc.js 代码检查配置 - 添加 .gitignore 版本控制忽略文件配置 - 添加 .prettierignore 格式化忽略配置 - 添加隐私协议HTML文件 - 添加API密钥管理组件基础结构
This commit is contained in:
127
src/components/IndustrySelect/index.vue
Normal file
127
src/components/IndustrySelect/index.vue
Normal file
@@ -0,0 +1,127 @@
|
||||
<!-- 省市区级联选择器 -->
|
||||
<template>
|
||||
<a-cascader
|
||||
:value="value"
|
||||
:options="regionsData"
|
||||
:show-search="showSearch"
|
||||
:placeholder="placeholder"
|
||||
dropdown-class-name="ele-pop-wrap-higher"
|
||||
@update:value="updateValue"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import type { ValueType } from 'ant-design-vue/es/vc-cascader/Cascader';
|
||||
import type { IndustryData } from './types';
|
||||
import { getIndustryData } from './load-data';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
value?: string[];
|
||||
placeholder?: string;
|
||||
options?: IndustryData[];
|
||||
valueField?: 'label';
|
||||
type?: 'provinceCity' | 'province';
|
||||
showSearch?: boolean;
|
||||
}>(),
|
||||
{
|
||||
showSearch: true
|
||||
}
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:value', value?: string[]): void;
|
||||
(e: 'load-data-done', value: IndustryData[]): void;
|
||||
}>();
|
||||
|
||||
// 级联选择器数据
|
||||
const regionsData = ref<IndustryData[]>([]);
|
||||
|
||||
/* 更新 value */
|
||||
const updateValue = (value: ValueType) => {
|
||||
emit('update:value', value as string[]);
|
||||
};
|
||||
|
||||
/* 级联选择器数据 value 处理 */
|
||||
const formatData = (data: IndustryData[]) => {
|
||||
if (props.valueField === 'label') {
|
||||
return data.map((d) => {
|
||||
const item: IndustryData = {
|
||||
label: d.label,
|
||||
value: d.label
|
||||
};
|
||||
if (d.children) {
|
||||
item.children = d.children.map((c) => {
|
||||
const cItem: IndustryData = {
|
||||
label: c.label,
|
||||
value: c.label
|
||||
};
|
||||
if (c.children) {
|
||||
cItem.children = c.children.map((cc) => {
|
||||
return {
|
||||
label: cc.label,
|
||||
value: cc.label
|
||||
};
|
||||
});
|
||||
}
|
||||
return cItem;
|
||||
});
|
||||
}
|
||||
return item;
|
||||
});
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
/* 省市区数据筛选 */
|
||||
const filterData = (data: IndustryData[]) => {
|
||||
if (props.type === 'provinceCity') {
|
||||
return formatData(
|
||||
data.map((d) => {
|
||||
const item: IndustryData = {
|
||||
label: d.label,
|
||||
value: d.value
|
||||
};
|
||||
if (d.children) {
|
||||
item.children = d.children.map((c) => {
|
||||
return {
|
||||
label: c.label,
|
||||
value: c.value
|
||||
};
|
||||
});
|
||||
}
|
||||
return item;
|
||||
})
|
||||
);
|
||||
} else if (props.type === 'province') {
|
||||
return formatData(
|
||||
data.map((d) => {
|
||||
return {
|
||||
label: d.label,
|
||||
value: d.value
|
||||
};
|
||||
})
|
||||
);
|
||||
} else {
|
||||
return formatData(data);
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.options,
|
||||
(options) => {
|
||||
regionsData.value = filterData(options ?? []);
|
||||
if (!options) {
|
||||
getIndustryData().then((data) => {
|
||||
regionsData.value = filterData(data ?? []);
|
||||
emit('load-data-done', data);
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
immediate: true
|
||||
}
|
||||
);
|
||||
</script>
|
||||
25
src/components/IndustrySelect/load-data.ts
Normal file
25
src/components/IndustrySelect/load-data.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import request from '@/utils/request';
|
||||
import type { IndustryData } from './types';
|
||||
const BASE_URL = import.meta.env.BASE_URL;
|
||||
let reqPromise: Promise<IndustryData[]>;
|
||||
|
||||
/**
|
||||
* 获取省市区数据
|
||||
*/
|
||||
export function getIndustryData() {
|
||||
if (!reqPromise) {
|
||||
reqPromise = new Promise<IndustryData[]>((resolve, reject) => {
|
||||
request
|
||||
.get<IndustryData[]>(BASE_URL + 'json/industry-data.json', {
|
||||
baseURL: ''
|
||||
})
|
||||
.then((res) => {
|
||||
resolve(res.data ?? []);
|
||||
})
|
||||
.catch((e) => {
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
return reqPromise;
|
||||
}
|
||||
15
src/components/IndustrySelect/types/index.ts
Normal file
15
src/components/IndustrySelect/types/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 行业类型
|
||||
*/
|
||||
export interface IndustryData {
|
||||
label: string;
|
||||
value: string;
|
||||
children?: {
|
||||
value: string;
|
||||
label: string;
|
||||
children?: {
|
||||
value: string;
|
||||
label: string;
|
||||
}[];
|
||||
}[];
|
||||
}
|
||||
Reference in New Issue
Block a user