homePage.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 } 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. if (!url[1]) {
  26. wechatAuth();
  27. } else {
  28. codeStr = codeStr.split("&");
  29. codeStr = codeStr[0];
  30. uni.showLoading({
  31. title: "登录中",
  32. mask: true,
  33. });
  34. api_wechatLoginEncrypt({
  35. code:codeStr
  36. }).then(res => {
  37. uni.hideLoading();
  38. if (res.status == 200) {
  39. loginSuccess(res.user);
  40. getConfig();
  41. } else if (res.status == 501) {
  42. uni.showModal({
  43. title: '提示',
  44. content: '您的账号被删除,请联系管理员',
  45. showCancel: false,
  46. confirmColor: defaultColor,
  47. confirmText: '取消',
  48. });
  49. } else if (res.status == 403) {
  50. uni.reLaunch({
  51. url: `/pages/initBind/initBind?wechat=${res.wechat}`
  52. })
  53. } else {
  54. uni.showToast({
  55. icon: 'none',
  56. title: res.remarks || '请求数据失败!'
  57. });
  58. }
  59. });
  60. }
  61. }
  62. /**
  63. * 账号密码登录
  64. */
  65. function loginEncrypt(username, password) {
  66. uni.showLoading({
  67. title: "登录中",
  68. mask: true,
  69. });
  70. let postData = {
  71. k: encryptByEnAESLogin(JSON.stringify({username, password}))
  72. };
  73. api_loginEncrypt(postData).then(res => {
  74. uni.hideLoading();
  75. getConfig();
  76. if (res.state == 200) {
  77. loginSuccess(res.data);
  78. } else {
  79. uni.showToast({
  80. icon: 'none',
  81. title: res.remarks || '请求数据失败!'
  82. });
  83. }
  84. });
  85. }
  86. // 获取配置项
  87. function getConfig(){
  88. api_systemConfiguration({
  89. idx: 0,
  90. sum: 9999,
  91. }).then(res=>{
  92. uni.setStorageSync('sysData',JSON.stringify(res.list))
  93. })
  94. }
  95. onLoad((option) => {
  96. uni.clearStorageSync();
  97. // 获取当前页面的实例
  98. const pages = getCurrentPages();
  99. const currentPage = pages[pages.length - 1];
  100. // 获取URL参数
  101. const options = currentPage.options;
  102. if (process.env.NODE_ENV === 'development' && options.username && options.password) {
  103. // http://localhost:8081/user/#/?username=liaomingming&password=Dstech@123
  104. // 本地开发调试用
  105. loginEncrypt(options.username, options.password)
  106. } else {
  107. wechatLoginEncrypt();
  108. }
  109. })
  110. </script>