import http, { takeBackUrl } from '@/utils/http'; import DictCache from '@/utils/dict'; import { stringify } from 'qs'; /** * 忘记密码 * page func * parameter: { } * @param parameter * @returns {*} */ export function forgetPwd(parameter) { return http({ url: '/ignores/forget-pwd', method: 'put', data: parameter }); } /** * 获取图片验证码 */ export function getCode(data) { return http({ url: '/service/sms/sendSms', method: 'POST', data }); } /** * 获取用户详情,包括权限 */ export function getUserInfo() { return http({ url: '/upms/users/info', method: 'get' }); } /** * 获取用户详情 */ export function getUserInfoModel() { return http({ url: '/upms/users/info/model', method: 'get' }); } /** * 退出登录 */ export function userLogout() { return http({ url: '/upms/users/logout', method: 'delete' }); } /** * 获取数据词典 */ export function getDictData() { return http({ url: '/upms/dicts/data', method: 'get' }); } /** * 登录 */ export function mobileLogin(data) { return new Promise((resolve, reject) => { http({ url: '/oauth/token', method: 'GET', data }) .then(res => { // 存入用户信息 // 获取用户信息 // TODO future 没有做容错,完成再调试 // 存入token uni.setStorage({ key: 'accessToken', data: res.data.access_token, success: function () { // 获取词典 getDictData().then(response => { // 登录前由操作拦截/401 或页面鉴权记录了来源页,优先回跳 const backUrl = takeBackUrl(); const backIsTab = uni.getStorageSync('login_back_is_tab'); uni.removeStorageSync('login_back_is_tab'); // 快捷登录 OAuth 回调后应用重启,首页可能是页面栈中唯一的页面 // uni.redirectTo 无法关闭栈中最后一个页面,此时需用 reLaunch const onlyOnePage = getCurrentPages().length <= 1; if (backUrl) { if (backIsTab) { // tabBar 页面必须用 switchTab,redirectTo 无法跳转 uni.switchTab({ url: backUrl.split('?')[0], fail: function () { uni.switchTab({ url: '/pages/tidings/tidings' }); } }); } else if (onlyOnePage) { uni.reLaunch({ url: backUrl, fail: function () { uni.switchTab({ url: '/pages/tidings/tidings' }); } }); } else { uni.redirectTo({ url: backUrl, fail: function () { // redirectTo 失败(可能是 tabBar 页面),降级为 switchTab uni.switchTab({ url: backUrl.split('?')[0], fail: function () { uni.switchTab({ url: '/pages/tidings/tidings' }); } }); } }); } } else { uni.switchTab({ url: '/pages/tidings/tidings' }); } uni.setStorage({ key: DictCache.BASE_DATA_CACHE, data: response.data, success: function () {} }); }); // 获取登录人信息 这一步可以不用,移动端可以在使用用户的时候再获取,这个方法是留着渲染动态路由的 getUserInfo().then(response => { uni.setStorage({ key: 'userInfo', data: response.data, success: function () { resolve(res); } }); }); } }); }) .catch(err => reject(err)); }); } /** * fetch single func * parameter: { } * @param parameter * @returns {*} */ export function fetchSbInfoIgnores(parameter) { return http({ url: '/ignores/sb/' + parameter.id, method: 'get', headers: { 'Content-Type': 'application/json;charset=UTF-8' } }); } /** * 更新设备图片 */ export function updateSbInfoImagesIgnores (parameter) { return http({ url: '/ignores/sb/images/' + parameter.id, method: 'PUT', data: parameter }) } /** * 添加报修 */ export function addRepairApplicationFormIgnores (parameter) { return http({ url: '/ignores/repair/add', method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json;charset=UTF-8' }, data: parameter }) } /** * page func * parameter: { } * @param parameter * @returns {*} */ export function getSbTaskIgnores (parameter) { return http({ url: '/ignores/sb/task2/' + parameter.id, method: 'get', headers: { 'Content-Type': 'application/json;charset=UTF-8' } }) } /** * 设备近期点检日历(数据源为保养任务),按月返回已完成的保养任务,已完成的日期在日历上标绿打勾 * parameter: { sbId, month } month 形如 2026-10,不传默认当月 */ export function getSbCheckCalendarIgnores (parameter) { return http({ url: '/ignores/sb/check-calendar/' + parameter.sbId + '?' + stringify({ month: parameter.month }), method: 'get', headers: { 'Content-Type': 'application/json;charset=UTF-8' } }) } // /** // * page func // * parameter: { } // * @param parameter // * @returns {*} // */ // export function getSbTaskIgnores (parameter) { // return http({ // url: '/ignores/sb/task/' + parameter.id, // method: 'get', // headers: { // 'Content-Type': 'application/json;charset=UTF-8' // } // }) // } export function getCheckJobPageIgnores (parameter) { return http({ url: '/ignores/check/sb/jobs/page?' + stringify(parameter), method: 'get', headers: { 'Content-Type': 'application/json;charset=UTF-8' } }) } export function fetchCheckJobIgnores (parameter) { return http({ url: '/ignores/check/jobs/' + parameter.id, method: 'get', headers: { 'Content-Type': 'application/json;charset=UTF-8' } }) } export function executeJobIgnores (parameter) { return http({ url: '/ignores/check/jobs/execute', method: 'PUT', data: parameter }) } export function finishJobIgnores (parameter) { return http({ url: '/ignores/check/jobs/finish', method: 'PUT', data: parameter }) } /** * 添加设备状态变更记录 */ export function addSbStatusLogIgnores (parameter) { return http({ url: '/ignores/sb/status-logs', method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json;charset=UTF-8' }, data: parameter }) } export function getCheckJobDetail (parameter) { return http({ url: '/check/jobs/getCheckJobVO/detail?' + stringify(parameter), method: 'get', headers: { 'Content-Type': 'application/json;charset=UTF-8' } }) } export function getCheckJob (parameter) { return http({ url: '/check/jobs/getCheckJobVO?' + stringify(parameter), method: 'get', headers: { 'Content-Type': 'application/json;charset=UTF-8' } }) }