import axios from 'axios' axios.defaults.crossDomain = true axios.defaults.headers.common['token'] = 'token' axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' axios.defaults.withCredentials = true axios.interceptors.request.use((config) => { config.url = config.url || '/dostar' config.method = 'post' config.data = config.data || {} if (config.url !== '/login') { config.data.userid = sessionStorage.getItem('UserID') || '' } config.data = JSON.stringify(config.data) return config }, (error) => { return Promise.reject(error) }) axios.interceptors.response.use((response) => { return Promise.resolve(response.data) }, (error) => { return Promise.reject(error) }) class Api { constructor() { if (process.env.NODE_ENV === 'production') { axios.defaults.baseURL = document.location.origin + '/' + window.Glob.Service } else { axios.defaults.baseURL = 'http://127.0.0.1:8888' } } /** * @description 登录系统 */ loginsystem (username, password) { return axios({ url: '/login', data: { Username: username, Password: password } }) } /** * @description 登出系统 */ logoutsystem () { return axios({ url: '/dostar', data: { func: 'logout' } }) } /** * @description 重置密码 */ resetpassword (originpwd, newpwd) { return axios({ url: '/dostar', data: { func: 'ResetPassword', OriginPwd: originpwd, NewPwd: newpwd } }) } /** * @description 获取主菜单数据 */ getMainMenuData () { return axios({ url: '/dostar', data: { func: 'GetTopMenus' } }) } /** * @description 获取子菜单数据 * @param {String} menuId 主菜单Id */ getSubMenuData (menuId) { return axios({ url: '/dostar', data: { func: 'GetSubMenus', ParentID: menuId } }) } /** * @description 获取页面配置信息 * @param {String} MenuNo 页面菜单参数 */ getMainConfigsData (MenuNo) { return axios({ url: '/dostar', data: { func: 'GetMainConfigs', MenuNo: MenuNo } }) } /** * @description 获取页面列表数据 * @param {String} MenuNo 页面菜单参数 */ getMainTableData (MenuNo, pageIndex = 1, pageSize = 10, orderColumn = '', orderType = '', search) { return axios({ url: '/dostar', data: { func: 'GetMainData', MenuNo: MenuNo, PageIndex: pageIndex, PageSize: pageSize, orderColumn: orderColumn, orderType: orderType, search: search } }) } } export default new Api()