فهرست منبع

修复DySelectTree远程请求的错误

Yue 2 سال پیش
والد
کامیت
0b16bec60a
4فایلهای تغییر یافته به همراه34 افزوده شده و 8 حذف شده
  1. 2 0
      components.d.ts
  2. 1 1
      src/components/Tree/OrgCompany.vue
  3. 1 1
      src/components/select/DySelect.vue
  4. 30 6
      src/components/select/DySelectTree.vue

+ 2 - 0
components.d.ts

@@ -35,6 +35,8 @@ declare module '@vue/runtime-core' {
     ElOption: typeof import('element-plus/es')['ElOption']
     ElPagination: typeof import('element-plus/es')['ElPagination']
     ElRadio: typeof import('element-plus/es')['ElRadio']
+    ElRadioButton: typeof import('element-plus/es')['ElRadioButton']
+    ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
     ElRow: typeof import('element-plus/es')['ElRow']
     ElSelect: typeof import('element-plus/es')['ElSelect']
     ElTree: typeof import('element-plus/es')['ElTree']

+ 1 - 1
src/components/Tree/OrgCompany.vue

@@ -170,7 +170,7 @@ onMounted(() => {
 
 <style lang="scss" scoped>
 :deep(.el-tree-node) {
-  &__content {
+  .el-tree-node__content {
     height: 35px;
     color: #181c32;
     justify-content: space-between;

+ 1 - 1
src/components/select/DySelect.vue

@@ -106,7 +106,7 @@ function loadData() {
         processData(res.data)
       })
     } else if (props.method.toLowerCase() == "post") {
-      Rs.get(configs).then((res: any) => {
+      Rs.post(configs).then((res: any) => {
         processData(res.data)
       })
     }

+ 30 - 6
src/components/select/DySelectTree.vue

@@ -14,6 +14,7 @@ const props = withDefaults(
     value: string | null | undefined
     name?: string
     url?: string
+    method?: string
     configs?: AxiosRequestConfig
     multiple?: boolean
     clearable?: boolean
@@ -34,6 +35,7 @@ const props = withDefaults(
     multiple: false,
     clearable: false,
     searchable: false,
+    method: "get",
     staticOptions: () => {
       return [] as Array<TreeOption>
     },
@@ -70,7 +72,7 @@ function formatData(data: any) {
     if (props.optionMap.children in data) {
       const childrenItem = [] as Array<TreeOption>
       const children = data[props.optionMap.children]
-      children.forEach((v: any) => {
+      children?.forEach((v: any) => {
         childrenItem.push(formatData(v))
       })
       item.children = childrenItem
@@ -81,10 +83,8 @@ function formatData(data: any) {
 
 function init() {
   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)
         options.value.push(item)
       })
@@ -92,7 +92,31 @@ function init() {
         const val = options.value[0].id
         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) {