homePage.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view>
  3. </view>
  4. </template>
  5. <script setup>
  6. // 添加路由拦截
  7. import '@/interceptor/routeInterceptor.js'
  8. import { encryptByEnAESLogin } from '@/utils/index.js'
  9. import { onLoad } from '@dcloudio/uni-app'
  10. import { defaultColor } from '@/static/js/theme.js'
  11. import { api_wechatLoginEncrypt, api_loginEncrypt, api_systemConfiguration, api_getDictionary} from "@/http/api.js"
  12. import { useWechatAuth } from '@/share/useWechatAuth.js'
  13. import { useLoginSuccess } from '@/share/useLoginSuccess.js'
  14. import { useSetTitle } from '@/share/useSetTitle.js'
  15. useSetTitle()
  16. const { wechatAuth } = useWechatAuth()
  17. const { loginSuccess } = useLoginSuccess()
  18. /**
  19. * 微信登录
  20. */
  21. function wechatLoginEncrypt() {
  22. const url = window.location.href.split("?");
  23. let wenhaohoumian = window.location.href.split("?code="); //截取问号地址数组
  24. let codeStr = wenhaohoumian[1]; //地址数组赋值
  25. let loginType = url[1].split("#/")
  26. let str = loginType[0].split("=")
  27. console.log(777878,str)
  28. if(str[0]=='loginType'){
  29. uni.setStorageSync('loginType',str[1])
  30. if (!url[2]) {
  31. wechatAuth();
  32. } else {
  33. codeStr = codeStr.split("&");
  34. codeStr = codeStr[0];
  35. uni.showLoading({
  36. title: "登录中",
  37. mask: true,
  38. });
  39. api_wechatLoginEncrypt({
  40. code:codeStr
  41. }).then(res => {
  42. uni.hideLoading();
  43. if (res.status == 200) {
  44. loginSuccess(res.user);
  45. getConfig();
  46. changeGroup();
  47. } else if (res.status == 501) {
  48. uni.showModal({
  49. title: '提示',
  50. content: '您的账号被删除,请联系管理员',
  51. showCancel: false,
  52. confirmColor: defaultColor,
  53. confirmText: '取消',
  54. });
  55. } else if (res.status == 555) {
  56. uni.reLaunch({
  57. url: `/pages/initBind/initBind?wechat=${res.wechat}`
  58. })
  59. } else {
  60. uni.showToast({
  61. icon: 'none',
  62. title: res.remarks || '请求数据失败!'
  63. });
  64. }
  65. });
  66. }
  67. }else{
  68. uni.setStorageSync('loginType','2')
  69. if (!url[1]) {
  70. wechatAuth();
  71. } else {
  72. codeStr = codeStr.split("&");
  73. codeStr = codeStr[0];
  74. uni.showLoading({
  75. title: "登录中",
  76. mask: true,
  77. });
  78. api_wechatLoginEncrypt({
  79. code:codeStr
  80. }).then(res => {
  81. uni.hideLoading();
  82. if (res.status == 200) {
  83. loginSuccess(res.user);
  84. getConfig();
  85. changeGroup();
  86. } else if (res.status == 501) {
  87. uni.showModal({
  88. title: '提示',
  89. content: '您的账号被删除,请联系管理员',
  90. showCancel: false,
  91. confirmColor: defaultColor,
  92. confirmText: '取消',
  93. });
  94. } else if (res.status == 555) {
  95. uni.reLaunch({
  96. url: `/pages/initBind/initBind?wechat=${res.wechat}`
  97. })
  98. } else {
  99. uni.showToast({
  100. icon: 'none',
  101. title: res.remarks || '请求数据失败!'
  102. });
  103. }
  104. });
  105. }
  106. }
  107. }
  108. /**
  109. * 账号密码登录
  110. */
  111. function loginEncrypt(username, password) {
  112. uni.showLoading({
  113. title: "登录中",
  114. mask: true,
  115. });
  116. let postData = {
  117. k: encryptByEnAESLogin(JSON.stringify({username, password}))
  118. };
  119. api_loginEncrypt(postData).then(res => {
  120. uni.hideLoading();
  121. getConfig();
  122. changeGroup();
  123. if (res.state == 200) {
  124. loginSuccess(res.data);
  125. } else {
  126. uni.showToast({
  127. icon: 'none',
  128. title: res.remarks || '请求数据失败!'
  129. });
  130. }
  131. });
  132. }
  133. // 获取配置项
  134. function getConfig(){
  135. api_systemConfiguration({
  136. idx: 0,
  137. sum: 9999,
  138. }).then(res=>{
  139. uni.setStorageSync('sysData',JSON.stringify(res.list))
  140. })
  141. }
  142. // 获取工作组
  143. function changeGroup(){
  144. let postData = {
  145. "key": 'usertype',
  146. "type": "list",
  147. };
  148. api_getDictionary(postData).then((data) => {
  149. uni.setStorageSync('groupData',JSON.stringify(data))
  150. });
  151. }
  152. onLoad((option) => {
  153. uni.clearStorageSync();
  154. // 获取当前页面的实例
  155. const pages = getCurrentPages();
  156. const currentPage = pages[pages.length - 1];
  157. // 获取URL参数
  158. const options = currentPage.options;
  159. if (process.env.NODE_ENV === 'development' && options.username && options.password) {
  160. // http://localhost:8081/user/#/?username=liaomingming&password=Dstech@123
  161. // 本地开发调试用
  162. loginEncrypt(options.username, options.password)
  163. } else {
  164. wechatLoginEncrypt();
  165. }
  166. })
  167. </script>