|  |  |  | import { createStore as create } from 'vuex'; | 
					
						
							|  |  |  | import { Styles, Size } from '../config'; | 
					
						
							|  |  |  | import { getByCodes, getInfo } from '../api/public'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class State { | 
					
						
							|  |  |  |   dict = { | 
					
						
							|  |  |  |     active_status: { | 
					
						
							|  |  |  |       A: '启用', | 
					
						
							|  |  |  |       B: '禁用', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     test: { | 
					
						
							|  |  |  |       a: 'A', | 
					
						
							|  |  |  |       b: 'B', | 
					
						
							|  |  |  |       c: 'C', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   style = Styles.plain; | 
					
						
							|  |  |  |   size = Size.normal; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class Actions { | 
					
						
							|  |  |  |   getDictMap = ({ state, commit }, codes) => { | 
					
						
							|  |  |  |     if (codes == null) { | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     const arr: Array<any> = []; | 
					
						
							|  |  |  |     for (let i = 0; i < codes.length; i++) { | 
					
						
							|  |  |  |       const code = codes[i]; | 
					
						
							|  |  |  |       state.dict[code] || arr.push(code); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (arr.length == 0) { | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     getByCodes({ codes: arr.join() }).then((rsp: any) => { | 
					
						
							|  |  |  |       if (rsp) { | 
					
						
							|  |  |  |         for (let i = 0; i < arr.length; i++) { | 
					
						
							|  |  |  |           const key = arr[i]; | 
					
						
							|  |  |  |           const dict = {}; | 
					
						
							|  |  |  |           if (rsp[key]) { | 
					
						
							|  |  |  |             rsp[key].forEach((item) => { | 
					
						
							|  |  |  |               dict[item.code] = item.name; | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           commit('updateDict', [key, dict]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class Mutations { | 
					
						
							|  |  |  |   updateState = (state, param) => { | 
					
						
							|  |  |  |     state[param[0]] = param[1]; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   initSize = (state, height) => { | 
					
						
							|  |  |  |     const size = state.size; | 
					
						
							|  |  |  |     const head = parseInt(size.headHeight); | 
					
						
							|  |  |  |     const mainPad = parseInt(size.mainPad); | 
					
						
							|  |  |  |     const searchRow = parseInt(size.searchRowHeight); | 
					
						
							|  |  |  |     const searchRowPad = parseInt(size.searchRowPad); | 
					
						
							|  |  |  |     if (height) { | 
					
						
							|  |  |  |       size.height = height; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       height = size.height; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     size.mainHeight = Math.floor(height - head) + 'px'; | 
					
						
							|  |  |  |     size.tableHeight = | 
					
						
							|  |  |  |       height - 2 * (mainPad + searchRowPad) - 3 - searchRow - head; | 
					
						
							|  |  |  |     size.pTableHeight = size.tableHeight - size.pageHeight; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   updateDict = (state, param) => { | 
					
						
							|  |  |  |     state.dict[param[0]] = param[1]; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface StoreOptions { | 
					
						
							|  |  |  |   state?: State; | 
					
						
							|  |  |  |   getters?; | 
					
						
							|  |  |  |   actions?; | 
					
						
							|  |  |  |   mutations?: Mutations; | 
					
						
							|  |  |  |   modules?; | 
					
						
							|  |  |  |   plugins?; | 
					
						
							|  |  |  |   strict?: boolean; | 
					
						
							|  |  |  |   devtools?: boolean; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const createStore = (options) => { | 
					
						
							|  |  |  |   return create(options); | 
					
						
							|  |  |  | }; |