File size: 4,934 Bytes
6b8fc2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import { Effect, Reducer, Subscription } from 'umi';
import { message } from 'antd';
import { addParam } from '@/utils';
import userService from '@/services/userService';
import { rearg } from 'lodash';

export interface settingModelState {
  isShowPSwModal: boolean;
  isShowTntModal: boolean;
  isShowSAKModal: boolean;
  isShowSSModal: boolean;
  llm_factory: string;
  loading: boolean;
  tenantIfo: any,
  llmInfo: any,
  myLlm: any[],
  factoriesList: any[]
}

export interface settingModelType {
  namespace: 'settingModel';
  state: settingModelState;
  effects: {
    setting: Effect;
    getUserInfo: Effect;
    getTenantInfo: Effect;
    set_tenant_info: Effect;
    factories_list: Effect;
    llm_list: Effect;
    my_llm: Effect;
    set_api_key: Effect;
  };
  reducers: {
    updateState: Reducer<settingModelState>;
  };
  subscriptions: { setup: Subscription };
}
const Model: settingModelType = {
  namespace: 'settingModel',
  state: {
    isShowPSwModal: false,
    isShowTntModal: false,
    isShowSAKModal: false,
    isShowSSModal: false,
    llm_factory: '',
    loading: false,
    tenantIfo: {},
    llmInfo: {},
    myLlm: [],
    factoriesList: []
  },
  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(location => {
      });
    }
  },
  effects: {
    *setting({ payload = {}, callback }, { call, put }) {
      const { data, response } = yield call(userService.setting, payload);
      const { retcode, data: res, retmsg } = data
      if (retcode === 0) {
        message.success('密码修改成功!');
        callback && callback()
      }
    },
    *getUserInfo({ payload = {} }, { call, put }) {
      const { data, response } = yield call(userService.user_info, payload);
      const { retcode, data: res, retmsg } = data
      const userInfo = {
        avatar: res.avatar,
        name: res.nickname,
        email: res.email
      };
      localStorage.setItem('userInfo', JSON.stringify(userInfo))
      if (retcode === 0) {
        // localStorage.setItem('userInfo',res.)
      }
    },
    *getTenantInfo({ payload = {} }, { call, put }) {
      yield put({
        type: 'updateState',
        payload: {
          loading: true
        }
      });
      const { data, response } = yield call(userService.get_tenant_info, payload);
      const { retcode, data: res, retmsg } = data
      // llm_id 对应chat_id
      // asr_id 对应speech2txt

      yield put({
        type: 'updateState',
        payload: {
          loading: false
        }
      });
      if (retcode === 0) {
        res.chat_id = res.llm_id
        res.speech2text_id = res.asr_id
        yield put({
          type: 'updateState',
          payload: {
            tenantIfo: res
          }
        });
      }
    },
    *set_tenant_info({ payload = {} }, { call, put }) {
      const { data, response } = yield call(userService.set_tenant_info, payload);
      const { retcode, data: res, retmsg } = data
      // llm_id 对应chat_id
      // asr_id 对应speech2txt
      if (retcode === 0) {
        yield put({
          type: 'updateState',
          payload: {
            isShowSSModal: false
          }
        });
        yield put({
          type: 'getTenantInfo'
        })
      }
    },

    *factories_list({ payload = {} }, { call, put }) {
      const { data, response } = yield call(userService.factories_list, payload);
      const { retcode, data: res, retmsg } = data
      if (retcode === 0) {
        yield put({
          type: 'updateState',
          payload: {
            factoriesList: res
          }
        });
      }
    },
    *llm_list({ payload = {} }, { call, put }) {
      const { data, response } = yield call(userService.llm_list, payload);
      const { retcode, data: res, retmsg } = data
      if (retcode === 0) {
        yield put({
          type: 'updateState',
          payload: {
            llmInfo: res
          }
        });
      }
    },
    *my_llm({ payload = {} }, { call, put }) {
      const { data, response } = yield call(userService.my_llm, payload);
      const { retcode, data: res, retmsg } = data
      if (retcode === 0) {
        yield put({
          type: 'updateState',
          payload: {
            myLlm: res
          }
        });
      }
    },
    *set_api_key({ payload = {}, callback }, { call, put }) {
      const { data, response } = yield call(userService.set_api_key, payload);
      const { retcode, data: res, retmsg } = data
      if (retcode === 0) {
        message.success('设置API KEY成功!');
        callback && callback()
      }
    },
  },
  reducers: {
    updateState(state, { payload }) {
      return {
        ...state,
        ...payload
      };
    }
  }
};
export default Model;