Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

选择器加载异步数据token #84

Open
fengbindev opened this issue Apr 27, 2023 · 5 comments
Open

选择器加载异步数据token #84

fengbindev opened this issue Apr 27, 2023 · 5 comments

Comments

@fengbindev
Copy link

fc-designer的选择器组件,在加载异步数据的时候怎么操作才能解决待token得问题???就是访问异步数据接口的时候能自带vue中的token??? 如: $store.user.token ,这种方式

@xaboy
Copy link
Owner

xaboy commented Apr 27, 2023

自己重写formCreate.fetch方法

@OlyLis1005
Copy link

修改这个文件 src/plugins/formCreate/index.ts

interface Option {
  action: string
  method?: AxiosMethod
  data?: object
  dataType?: object
  headers?: object
  withCredentials?: boolean
  onSuccess: (body: any) => void
  onError?: (e: Error | ProgressEvent) => void
  _parse?: string
}

// 参考 http://www.form-create.com/v3/element-ui/auto-import.html 文档
export const setupFormCreate = (app: App<Element>) => {
  components.forEach((component) => {
    app.component(component.name, component)
  })
  formCreate.use(install)

  const overrideFetch = (option: Option, effectArgs) => {
    // console.log('--fetch option--', option)

    serivice({
      url: option.action,
      method: option.method,
      data: option.data,
      headers: option.headers,
      withCredentials: option.withCredentials
    })
      .then((res) => {
        try {
          if (option._parse) {
            const parseFn = formCreate.parseFn(option._parse)
            // console.log('--parseFn--', parseFn)
            res.data = parseFn(res)
          }
        } catch (e) {
          console.log('--parseFn error--', e)
        }
        option.onSuccess?.(res)
      })
      .catch((e) => {
        option.onError?.(e)
      })

    return option
  }
  // 重写 fetch 请求方法,select 等动态获取数据请求通过拦截器
  formCreate.fetch = overrideFetch

  app.use(formCreate)
}

@rujianwang
Copy link

自己重写formCreate.fetch方法

请问下这个要怎么重写

@xaboy
Copy link
Owner

xaboy commented Mar 20, 2024

@rujianwang 看一下楼上的代码, 核心就是formCreate.fetch = overrideFetch 覆盖formCreate.fetch

@rujianwang
Copy link

@rujianwang 看一下楼上的代码, 核心就是formCreate.fetch = overrideFetch 覆盖formCreate.fetch

Vue.use(ELEMENT);

formCreate.fetch = function(option, effectArgs) {
debugger;
};
Vue.use(formCreate);

我在main.js里面这样写 默认不生效。我不太想 改你的源码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants