import { api_wechatAuth, api_systemConfiguration, api_getDictionary} from "@/http/api.js"
import { useLoginSuccess } from '@/share/useLoginSuccess.js'
const { loginSuccess } = useLoginSuccess()
export function useWechatAuth() {
  /**
   * 微信登录2
   */
  const wechatAuth = () => {
    uni.showLoading({
      title: "登录中",
      mask: true,
    });
    api_wechatAuth({
      redirectUrl: location.origin + location.pathname
    }).then(res => {
      uni.hideLoading();
      if (res.url) {
        window.location.href = res.url;
      } else {
        loginSuccess(res.user);
				api_systemConfiguration({
					idx: 0,
					sum: 9999,
				}).then(res2=>{
					uni.setStorageSync('sysData',JSON.stringify(res2.list))
				})
				
				let postData = {
					"key": 'usertype',
					"type": "list",
				};
				api_getDictionary(postData).then((data) => {
					uni.setStorageSync('groupData',JSON.stringify(data))
				});
      }
    });
  }

  return {
    wechatAuth
  };
}