| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import { getAccessToken } from '@/utils/auth'
- import { authLogin } from "@/api/login";
- import { setToken, setTenantId } from '@/utils/auth'
- import { openAuth } from "dingtalk-design-libs/biz/openAuth";
- import * as dd from "dingtalk-jsapi";
- // 登录页面
- const loginPage = "/pages/login"
- // 页面白名单
- const whiteList = [
- '/pages/login', '/pages/common/webview/index'
- ]
- // 检查地址白名单
- function checkWhite(url) {
- const path = url.split('?')[0]
- return whiteList.indexOf(path) !== -1
- }
- // 页面跳转验证拦截器
- let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
- list.forEach(item => {
- uni.addInterceptor(item, {
- invoke(to) {
- if (getAccessToken()) {
- if (to.path === loginPage) {
- uni.reLaunch({ url: "/" })
- }
- return true
- } else {
- if (dd.env.platform !== "notInDingTalk") {
- return new Promise((resolve, reject) => {
- dd.ready(function () {
- // 钉钉免登录认证-第三方企业
- // let corpId = that.$store.state.app.corpId;
- // console.log("corpId====", corpId);
- // 唤起授权--统一授权套件SDK
- openAuth({
- clientId: "suite7tssbigaaqsejgth", // 应用ID(唯一标识)
- corpId: corpId, // 当前组织的corpId
- rpcScope: "Contact.User.Read", //通讯录
- fieldScope: "Contact.User.mobile", //手机号
- type: 0, // 0 标识授权个人信息;1 标识授权组织信息
- }).then((res) => {
- // 处理返回数据
- console.log("统一授权套件SDK==res=", res);
- authLogin({ code: res.result.authCode, corpId: corpId.corpId })
- .then((res) => {
- console.log("===登录授权=", res);
- setToken(res.data);
- setTenantId(res.msg)
- next({ path: '/' })
- resolve();
- })
- .catch((err) => {
- reject();
- });
- });
- });
- });
- } else {
- if (checkWhite(to.url)) {
- return true
- }
- }
- uni.reLaunch({ url: loginPage })
- return false
-
- }
- },
- fail(err) {
- console.log(err)
- }
- })
- })
|