login.uts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import request from '@/utils/request'
  2. import sqlite from '@/utils/sqlite'
  3. export function offlineData(data:UTSJSONObject):Promise<UTSJSONObject> {
  4. return new Promise((resolve, reject) => {
  5. let result = JSON.parseObject(JSON.stringify(data)) as UTSJSONObject
  6. resolve(result)
  7. });
  8. }
  9. // 登录方法
  10. export function login(username:string, password:string, code:string, uuid:string):Promise<UTSJSONObject> {
  11. const data = {
  12. username,
  13. password,
  14. code,
  15. uuid
  16. } as UTSJSONObject
  17. let data2 = {
  18. username: "admin",
  19. password: "admin123",
  20. code: "",
  21. uuid: '1',
  22. token: '123456',
  23. roles:[] as string[]
  24. } as UTSJSONObject
  25. // #ifdef APP-ANDROID
  26. let result = sqlite.selectTableData('app_user','username',data['username'],'password',data['password']);
  27. console.log(result)
  28. // #endif
  29. /*
  30. return request({
  31. 'url': '/login',
  32. headers: {
  33. isToken: false
  34. },
  35. 'method': 'post',
  36. 'data': data
  37. })*/
  38. return offlineData(data2)
  39. }
  40. export type RegForm={
  41. username: string,
  42. password: string,
  43. confirmPassword: string,
  44. code: string,
  45. uuid: string
  46. }
  47. // 注册方法
  48. export function register(data:RegForm):Promise<UTSJSONObject> {
  49. return request({
  50. url: '/register',
  51. headers: {
  52. isToken: false
  53. },
  54. method: 'post',
  55. data
  56. })
  57. }
  58. // 获取用户详细信息
  59. export function getInfo():Promise<UTSJSONObject> {
  60. /*
  61. return request({
  62. 'url': '/getInfo',
  63. 'method': 'get'
  64. })*/
  65. let data = {
  66. username: "admin",
  67. password: "admin123",
  68. code: "",
  69. uuid: '1',
  70. token: '123456',
  71. roles:[] as string[]
  72. } as UTSJSONObject
  73. // #ifdef APP-ANDROID
  74. let result = sqlite.selectTableData('app_user','username',data['username'],'password',data['password']);
  75. console.log(result)
  76. // #endif
  77. return offlineData(data)
  78. }
  79. // 退出方法
  80. export function logout(token?:any):Promise<UTSJSONObject> {
  81. return request({
  82. 'url': '/logout',
  83. 'method': 'post'
  84. })
  85. }
  86. // 获取验证码
  87. export function getCodeImg():Promise<UTSJSONObject> {
  88. return request({
  89. 'url': '/captchaImage',
  90. headers: {
  91. isToken: false
  92. },
  93. method: 'get',
  94. timeout: 20000
  95. })
  96. }