|
@@ -14,6 +14,7 @@ const props = withDefaults(
|
|
|
value: string | null | undefined
|
|
value: string | null | undefined
|
|
|
name?: string
|
|
name?: string
|
|
|
url?: string
|
|
url?: string
|
|
|
|
|
+ method?: string
|
|
|
configs?: AxiosRequestConfig
|
|
configs?: AxiosRequestConfig
|
|
|
multiple?: boolean
|
|
multiple?: boolean
|
|
|
clearable?: boolean
|
|
clearable?: boolean
|
|
@@ -34,6 +35,7 @@ const props = withDefaults(
|
|
|
multiple: false,
|
|
multiple: false,
|
|
|
clearable: false,
|
|
clearable: false,
|
|
|
searchable: false,
|
|
searchable: false,
|
|
|
|
|
+ method: "get",
|
|
|
staticOptions: () => {
|
|
staticOptions: () => {
|
|
|
return [] as Array<TreeOption>
|
|
return [] as Array<TreeOption>
|
|
|
},
|
|
},
|
|
@@ -70,7 +72,7 @@ function formatData(data: any) {
|
|
|
if (props.optionMap.children in data) {
|
|
if (props.optionMap.children in data) {
|
|
|
const childrenItem = [] as Array<TreeOption>
|
|
const childrenItem = [] as Array<TreeOption>
|
|
|
const children = data[props.optionMap.children]
|
|
const children = data[props.optionMap.children]
|
|
|
- children.forEach((v: any) => {
|
|
|
|
|
|
|
+ children?.forEach((v: any) => {
|
|
|
childrenItem.push(formatData(v))
|
|
childrenItem.push(formatData(v))
|
|
|
})
|
|
})
|
|
|
item.children = childrenItem
|
|
item.children = childrenItem
|
|
@@ -81,10 +83,8 @@ function formatData(data: any) {
|
|
|
|
|
|
|
|
function init() {
|
|
function init() {
|
|
|
if (url?.value) {
|
|
if (url?.value) {
|
|
|
- const configs = Object.assign({}, { url: url.value, method: "get", successAlert: false }, props.configs)
|
|
|
|
|
- Rs.request(configs).then((res: any) => {
|
|
|
|
|
- //const data = [] as Array<TreeOption>
|
|
|
|
|
- res.data.forEach((v: any) => {
|
|
|
|
|
|
|
+ const processData = (data: any) => {
|
|
|
|
|
+ data.forEach((v: any) => {
|
|
|
const item = formatData(v)
|
|
const item = formatData(v)
|
|
|
options.value.push(item)
|
|
options.value.push(item)
|
|
|
})
|
|
})
|
|
@@ -92,7 +92,31 @@ function init() {
|
|
|
const val = options.value[0].id
|
|
const val = options.value[0].id
|
|
|
emits("update:value", val)
|
|
emits("update:value", val)
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ const configs = Object.assign({}, { url: url.value, successAlert: false }, props.configs)
|
|
|
|
|
+
|
|
|
|
|
+ if (props.method.toLowerCase() == "get") {
|
|
|
|
|
+ Rs.get(configs).then((res: any) => {
|
|
|
|
|
+ processData(res.data)
|
|
|
|
|
+ })
|
|
|
|
|
+ } else if (props.method.toLowerCase() == "post") {
|
|
|
|
|
+ Rs.post(configs).then((res: any) => {
|
|
|
|
|
+ processData(res.data)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //const configs = Object.assign({}, { url: url.value, method: "get", successAlert: false }, props.configs)
|
|
|
|
|
+ // Rs.request(configs).then((res: any) => {
|
|
|
|
|
+ // //const data = [] as Array<TreeOption>
|
|
|
|
|
+ // res.data.forEach((v: any) => {
|
|
|
|
|
+ // const item = formatData(v)
|
|
|
|
|
+ // options.value.push(item)
|
|
|
|
|
+ // })
|
|
|
|
|
+ // if (!value.value) {
|
|
|
|
|
+ // const val = options.value[0].id
|
|
|
|
|
+ // emits("update:value", val)
|
|
|
|
|
+ // }
|
|
|
|
|
+ // })
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
function onSelect(data: any) {
|
|
function onSelect(data: any) {
|