index.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. import http, { takeBackUrl } from '@/utils/http';
  2. import DictCache from '@/utils/dict';
  3. import { stringify } from 'qs';
  4. /**
  5. * 忘记密码
  6. * page func
  7. * parameter: { }
  8. * @param parameter
  9. * @returns {*}
  10. */
  11. export function forgetPwd(parameter) {
  12. return http({
  13. url: '/ignores/forget-pwd',
  14. method: 'put',
  15. data: parameter
  16. });
  17. }
  18. /**
  19. * 获取图片验证码
  20. */
  21. export function getCode(data) {
  22. return http({
  23. url: '/service/sms/sendSms',
  24. method: 'POST',
  25. data
  26. });
  27. }
  28. /**
  29. * 获取用户详情,包括权限
  30. */
  31. export function getUserInfo() {
  32. return http({
  33. url: '/upms/users/info',
  34. method: 'get'
  35. });
  36. }
  37. /**
  38. * 获取用户详情
  39. */
  40. export function getUserInfoModel() {
  41. return http({
  42. url: '/upms/users/info/model',
  43. method: 'get'
  44. });
  45. }
  46. /**
  47. * 退出登录
  48. */
  49. export function userLogout() {
  50. return http({
  51. url: '/upms/users/logout',
  52. method: 'delete'
  53. });
  54. }
  55. /**
  56. * 获取数据词典
  57. */
  58. export function getDictData() {
  59. return http({
  60. url: '/upms/dicts/data',
  61. method: 'get'
  62. });
  63. }
  64. /**
  65. * 登录
  66. */
  67. export function mobileLogin(data) {
  68. return new Promise((resolve, reject) => {
  69. http({
  70. url: '/oauth/token',
  71. method: 'GET',
  72. data
  73. })
  74. .then(res => {
  75. // 存入用户信息
  76. // 获取用户信息
  77. // TODO future 没有做容错,完成再调试
  78. // 存入token
  79. uni.setStorage({
  80. key: 'accessToken',
  81. data: res.data.access_token,
  82. success: function () {
  83. // 获取词典
  84. getDictData().then(response => {
  85. // 登录前由操作拦截/401 或页面鉴权记录了来源页,优先回跳
  86. const backUrl = takeBackUrl();
  87. const backIsTab = uni.getStorageSync('login_back_is_tab');
  88. uni.removeStorageSync('login_back_is_tab');
  89. // 快捷登录 OAuth 回调后应用重启,首页可能是页面栈中唯一的页面
  90. // uni.redirectTo 无法关闭栈中最后一个页面,此时需用 reLaunch
  91. const onlyOnePage = getCurrentPages().length <= 1;
  92. if (backUrl) {
  93. if (backIsTab) {
  94. // tabBar 页面必须用 switchTab,redirectTo 无法跳转
  95. uni.switchTab({
  96. url: backUrl.split('?')[0],
  97. fail: function () {
  98. uni.switchTab({ url: '/pages/tidings/tidings' });
  99. }
  100. });
  101. } else if (onlyOnePage) {
  102. uni.reLaunch({
  103. url: backUrl,
  104. fail: function () {
  105. uni.switchTab({ url: '/pages/tidings/tidings' });
  106. }
  107. });
  108. } else {
  109. uni.redirectTo({
  110. url: backUrl,
  111. fail: function () {
  112. // redirectTo 失败(可能是 tabBar 页面),降级为 switchTab
  113. uni.switchTab({
  114. url: backUrl.split('?')[0],
  115. fail: function () {
  116. uni.switchTab({ url: '/pages/tidings/tidings' });
  117. }
  118. });
  119. }
  120. });
  121. }
  122. } else {
  123. uni.switchTab({ url: '/pages/tidings/tidings' });
  124. }
  125. uni.setStorage({
  126. key: DictCache.BASE_DATA_CACHE,
  127. data: response.data,
  128. success: function () {}
  129. });
  130. });
  131. // 获取登录人信息 这一步可以不用,移动端可以在使用用户的时候再获取,这个方法是留着渲染动态路由的
  132. getUserInfo().then(response => {
  133. uni.setStorage({
  134. key: 'userInfo',
  135. data: response.data,
  136. success: function () {
  137. resolve(res);
  138. }
  139. });
  140. });
  141. }
  142. });
  143. })
  144. .catch(err => reject(err));
  145. });
  146. }
  147. /**
  148. * fetch single func
  149. * parameter: { }
  150. * @param parameter
  151. * @returns {*}
  152. */
  153. export function fetchSbInfoIgnores(parameter) {
  154. return http({
  155. url: '/ignores/sb/' + parameter.id,
  156. method: 'get',
  157. headers: {
  158. 'Content-Type': 'application/json;charset=UTF-8'
  159. }
  160. });
  161. }
  162. /**
  163. * 更新设备图片
  164. */
  165. export function updateSbInfoImagesIgnores (parameter) {
  166. return http({
  167. url: '/ignores/sb/images/' + parameter.id,
  168. method: 'PUT',
  169. data: parameter
  170. })
  171. }
  172. /**
  173. * 添加报修
  174. */
  175. export function addRepairApplicationFormIgnores (parameter) {
  176. return http({
  177. url: '/ignores/repair/add',
  178. method: 'POST',
  179. headers: {
  180. 'Accept': 'application/json',
  181. 'Content-Type': 'application/json;charset=UTF-8'
  182. },
  183. data: parameter
  184. })
  185. }
  186. /**
  187. * page func
  188. * parameter: { }
  189. * @param parameter
  190. * @returns {*}
  191. */
  192. export function getSbTaskIgnores (parameter) {
  193. return http({
  194. url: '/ignores/sb/task2/' + parameter.id,
  195. method: 'get',
  196. headers: {
  197. 'Content-Type': 'application/json;charset=UTF-8'
  198. }
  199. })
  200. }
  201. // /**
  202. // * page func
  203. // * parameter: { }
  204. // * @param parameter
  205. // * @returns {*}
  206. // */
  207. // export function getSbTaskIgnores (parameter) {
  208. // return http({
  209. // url: '/ignores/sb/task/' + parameter.id,
  210. // method: 'get',
  211. // headers: {
  212. // 'Content-Type': 'application/json;charset=UTF-8'
  213. // }
  214. // })
  215. // }
  216. export function getCheckJobPageIgnores (parameter) {
  217. return http({
  218. url: '/ignores/check/sb/jobs/page?' + stringify(parameter),
  219. method: 'get',
  220. headers: {
  221. 'Content-Type': 'application/json;charset=UTF-8'
  222. }
  223. })
  224. }
  225. export function fetchCheckJobIgnores (parameter) {
  226. return http({
  227. url: '/ignores/check/jobs/' + parameter.id,
  228. method: 'get',
  229. headers: {
  230. 'Content-Type': 'application/json;charset=UTF-8'
  231. }
  232. })
  233. }
  234. export function executeJobIgnores (parameter) {
  235. return http({
  236. url: '/ignores/check/jobs/execute',
  237. method: 'PUT',
  238. data: parameter
  239. })
  240. }
  241. export function finishJobIgnores (parameter) {
  242. return http({
  243. url: '/ignores/check/jobs/finish',
  244. method: 'PUT',
  245. data: parameter
  246. })
  247. }
  248. /**
  249. * 添加设备状态变更记录
  250. */
  251. export function addSbStatusLogIgnores (parameter) {
  252. return http({
  253. url: '/ignores/sb/status-logs',
  254. method: 'POST',
  255. headers: {
  256. 'Accept': 'application/json',
  257. 'Content-Type': 'application/json;charset=UTF-8'
  258. },
  259. data: parameter
  260. })
  261. }
  262. export function getCheckJobDetail (parameter) {
  263. return http({
  264. url: '/check/jobs/getCheckJobVO/detail?' + stringify(parameter),
  265. method: 'get',
  266. headers: {
  267. 'Content-Type': 'application/json;charset=UTF-8'
  268. }
  269. })
  270. }
  271. export function getCheckJob (parameter) {
  272. return http({
  273. url: '/check/jobs/getCheckJobVO?' + stringify(parameter),
  274. method: 'get',
  275. headers: {
  276. 'Content-Type': 'application/json;charset=UTF-8'
  277. }
  278. })
  279. }