Advertisement
golitter

Untitled

Jun 23rd, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1. import router from '@ohos.router'
  2. import fetch from '@system.fetch';
  3. import promptAction from '@ohos.promptAction';
  4. export default {
  5. goToRegeditPage(){
  6. console.info("login","点击了注册页面")
  7. router.replaceUrl({url:"pages/regedit/index"})
  8. },
  9. test_info(txt) {
  10. console.info("__TEST__: ", txt);
  11. },
  12. if_roles_login(formData, role) {
  13. console.info("__TEST__,"+JSON.stringify(formData))
  14. let ret_ok = false;
  15. fetch.fetch({
  16. url: this.$t("strings.url")+ role + '/login', //服务的地址
  17. data:formData.value, //可有可无,提交的数据
  18. method:"POST",
  19. header: {
  20. 'Content-Type': 'application/json'
  21. },
  22. success:(res) => {
  23. // this.test_info(JSON.parse(res.data).name === undefined)
  24. if(JSON.parse(res.data).name === undefined) {
  25. this.test_info("错误错误" + role)
  26. }
  27. if(JSON.parse(res.data).name != null){ //登录成功,res.data是json数据
  28. router.replaceUrl({url:"pages/main/index",params:JSON.parse(res.data)})
  29. ret_ok = true;
  30. }else{
  31. //登录失败进行Toast提示
  32. // promptAction.showToast({message:"账号或密码输入错误!",duration:5000})
  33. this.test_info("登录失败")
  34. }
  35. },
  36. });
  37. this.test_info(ret_ok)
  38. return ret_ok;
  39. },
  40. // TODO: 融合在同一个中
  41. if_cleaner_login(formData){
  42. console.info("__TEST__,"+JSON.stringify(formData))
  43. let ok = false;
  44. fetch.fetch({
  45. url: this.$t("strings.url")+'cleaner/login', //服务的地址
  46. data:formData.value, //可有可无,提交的数据
  47. method:"POST",
  48. header: {
  49. 'Content-Type': 'application/json'
  50. },
  51. success:(res) => {
  52. // this.test_info(JSON.parse(res.data).name === undefined)
  53. if(JSON.parse(res.data).name === undefined) {
  54. this.test_info("错误错误")
  55. }
  56. if(JSON.parse(res.data).name != null){ //登录成功,res.data是json数据
  57. router.replaceUrl({url:"pages/main/index",params:JSON.parse(res.data)})
  58. ok = true;
  59. }else{
  60. //登录失败进行Toast提示
  61. // promptAction.showToast({message:"账号或密码输入错误!",duration:5000})
  62. this.test_info("登录失败")
  63. }
  64. },
  65. });
  66. return ok
  67. },
  68. if_customer_login(formData){
  69. console.info("__TEST__,"+JSON.stringify(formData))
  70. let ok = false;
  71. fetch.fetch({
  72. url: this.$t("strings.url")+'customer/login', //服务的地址
  73. data:formData.value, //可有可无,提交的数据
  74. method:"POST",
  75. header: {
  76. 'Content-Type': 'application/json'
  77. },
  78. success:(res) => {
  79. // this.test_info(JSON.parse(res.data).name === undefined)
  80. if(JSON.parse(res.data).name === undefined) {
  81. this.test_info("错误错误")
  82. }
  83. if(JSON.parse(res.data).name != null){ //登录成功,res.data是json数据
  84. router.replaceUrl({url:"pages/main/index",params:JSON.parse(res.data)})
  85. ok = true;
  86. }else{
  87. //登录失败进行Toast提示
  88. // promptAction.showToast({message:"账号或密码输入错误!",duration:5000})
  89. this.test_info("登录失败")
  90. }
  91. },
  92. });
  93. return ok;
  94. },
  95. if_management_login(formData){
  96. console.info("__TEST__,"+JSON.stringify(formData))
  97. let ok = false;
  98. fetch.fetch({
  99. url: this.$t("strings.url")+'management/login', //服务的地址
  100. data:formData.value, //可有可无,提交的数据
  101. method:"POST",
  102. header: {
  103. 'Content-Type': 'application/json'
  104. },
  105. success:(res) => {
  106. // this.test_info(JSON.parse(res.data).name === undefined)
  107. if(JSON.parse(res.data).name === undefined) {
  108. this.test_info("错误错误")
  109. }
  110. if(JSON.parse(res.data).name != null){ //登录成功,res.data是json数据
  111. router.replaceUrl({url:"pages/main/index",params:JSON.parse(res.data)})
  112. ok = true;
  113. }else{
  114. //登录失败进行Toast提示
  115. // promptAction.showToast({message:"账号或密码输入错误!",duration:5000})
  116. this.test_info("登录失败")
  117. }
  118. },
  119. });
  120. return true;
  121. },
  122. dispose_diff_login(formData) {
  123. // this.test_info("dkkdjlkfj;sdkjf")
  124. // let hasName = this.if_cleaner_login(formData) === true;
  125. // if(hasName === false) hasName = this.if_customer_login(formData) === true;
  126. // if(hasName === false) hasName = this.if_management_login(formData) === true;
  127. // this.test_info(hasName);
  128. // if(hasName === false) {
  129. // promptAction.showToast({message:"账号或密码输入错误!",duration:5000})
  130. // this.test_info("都没有")
  131. // }
  132. this.test_info("start")
  133. let hasName = this.if_roles_login(formData, "cleaner") === true;
  134. if(hasName === false) hasName = this.if_roles_login(formData, "customer") === true;
  135. if(hasName === false) hasName = this.if_roles_login(formData, "management") === true;
  136. this.test_info("last " + hasName)
  137. if(hasName === false) {
  138. promptAction.showToast({message:"账号或密码输入错误!",duration:5000})
  139. this.test_info("都没有")
  140. }
  141. },
  142.  
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement