useWechatAuth.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { api_wechatAuth, api_systemConfiguration, api_getDictionary} from "@/http/api.js"
  2. import { useLoginSuccess } from '@/share/useLoginSuccess.js'
  3. const { loginSuccess, transform } = useLoginSuccess()
  4. export function useWechatAuth() {
  5. /**
  6. * 微信登录2
  7. */
  8. const wechatAuth = () => {
  9. uni.showLoading({
  10. title: "登录中",
  11. mask: true,
  12. });
  13. api_wechatAuth({
  14. redirectUrl: location.origin + location.pathname
  15. }).then(res => {
  16. uni.hideLoading();
  17. if (res.state == "200"){
  18. loginSuccess(res.user);
  19. transform(res.user);
  20. api_systemConfiguration({
  21. idx: 0,
  22. sum: 9999,
  23. }).then(res2=>{
  24. uni.setStorageSync('sysData',JSON.stringify(res2.list))
  25. })
  26. let postData = {
  27. "key": 'usertype',
  28. "type": "list",
  29. };
  30. api_getDictionary(postData).then((data) => {
  31. uni.setStorageSync('groupData',JSON.stringify(data))
  32. });
  33. } else if (res.state == "501"){
  34. uni.showModal({
  35. title: '提示',
  36. content: res.remarks,
  37. showCancel: false,
  38. confirmColor: '#49b856',
  39. success: function(res1) {
  40. if (res1.confirm) {
  41. console.log('用户点击确定');
  42. } else if (res1.cancel) {
  43. console.log('用户点击取消');
  44. }
  45. }
  46. });
  47. }else if (res.url){
  48. window.location.href = res.url;
  49. }
  50. });
  51. }
  52. return {
  53. wechatAuth
  54. };
  55. }