blank.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view class="blank-page">
  3. <van-empty v-if="noAuth" image="error" :description="noAuthDesc" />
  4. </view>
  5. </template>
  6. <script>
  7. import { getPlatformEnv } from "@/utils";
  8. import zlbConfig from "@/common/js/zlbConfig";
  9. import { getSsoUserInfo ,getSsoUserInfoUnity} from "@/api/user";
  10. import { storageUserInfo } from "@/utils/index";
  11. import Track from "@/common/js/track";
  12. import Vconsole from "vconsole";
  13. import dd from "gdt-jsapi";
  14. import {exemption, ZzdLogin, ZzdLogin1} from "@/api/system";
  15. import zlbApi from "@/api/zlbApi";
  16. const app = getApp();
  17. export default {
  18. name: "blank",
  19. components: {},
  20. props: {},
  21. data() {
  22. return {
  23. noAuth:true,
  24. noAuthDesc:'请使用浙政钉扫码登录'
  25. };
  26. },
  27. onUnload() {
  28. this.noAuth = false
  29. this.noAuthDesc = ""
  30. },
  31. onShow() {
  32. this.handleLogin()
  33. },
  34. methods: {
  35. // async getNewSsoUserInfo(ticket) {
  36. // const res = await getSsoUserInfoUnity({ ticketId: ticket });
  37. // const userInfo = res.data;
  38. // storageUserInfo({
  39. // nickName: userInfo.name,
  40. // avatarUrl: userInfo.headPicture,
  41. // phoneNumber: userInfo.phoneWx,
  42. // phoneWx: userInfo.phoneWx,
  43. // username: userInfo.name,
  44. // openId: userInfo.userIdZlb,
  45. // uuid: userInfo.uuid,
  46. // });
  47. // app.globalData.openid = userInfo.uuid;
  48. // // 开始埋点上报
  49. // this.startTrack();
  50. // if (app.globalData.options.code) {
  51. // uni.switchTab({
  52. // url: "/pages/home/home",
  53. // });
  54. // } else {
  55. // if (
  56. // userInfo.doorplateCount
  57. // ) {
  58. // uni.switchTab({
  59. // url: "/pages/home/home",
  60. // });
  61. // } else {
  62. // uni.reLaunch({
  63. // url: "/subPages/pages/scanCode/scanCode",
  64. // });
  65. // }
  66. // }
  67. // },
  68. // resolveParams(){
  69. // const params = this.getQuery(window.location.search);
  70. // if (params.qjw_debug) {
  71. // localStorage.setItem("debug", "true");
  72. // new Vconsole();
  73. // } else {
  74. // localStorage.setItem("debug", "false");
  75. // }
  76. // if (params.sp) {
  77. // console.error("sp", params.sp);
  78. // const spParams = this.getQuery(decodeURIComponent(params.sp));
  79. // console.error("spParams", spParams);
  80. // app.globalData.options = {
  81. // code: spParams.code,
  82. // };
  83. // }
  84. // //门牌code直接在链接上的话,说明从微信小程序过来
  85. // if (params.code) {
  86. // console.log("应该为微信环境,链接地址:", window.location.href);
  87. // console.error("code:", params.code);
  88. // app.globalData.options = {
  89. // code: params.code,
  90. // };
  91. // }
  92. // },
  93. // async unityLogin() {
  94. // this.resolveParams()
  95. // if (ZWJSBridge.ssoTicket) {
  96. // const ssoFlag = await ZWJSBridge.ssoTicket({});
  97. // if (ssoFlag && ssoFlag.result === true) {
  98. // //使用 IRS“浙里办”统一单点登录组件
  99. // if (ssoFlag.ticketId) {
  100. // // TODO 应用方服务端单点登录接口
  101. // app.globalData.isLogin = true;
  102. // this.getNewSsoUserInfo(ssoFlag.ticketId);
  103. // } else {
  104. // //当“浙里办”单点登录失败或登录态失效时调用 ZWJSBridge.openLink 方法重新获取ticketId。
  105. // this.login()
  106. // }
  107. // } else {
  108. // console.log('当前环境不支持 “浙里办”统一单点登录 ')
  109. // this.login()
  110. // }
  111. // } else {
  112. // console.log('ZWJSBridge 加载异常')
  113. // //异常情况:ZWJSBridge 加载异常
  114. // }
  115. // },
  116. // ssoLogin() {
  117. // const platformEnv = getPlatformEnv();
  118. // const params = this.getQuery(window.location.search);
  119. // let ssoUrl = "";
  120. // // 登录
  121. // if (platformEnv.bIsAlipayMini) {
  122. // console.log("支付宝环境单点登录");
  123. // ssoUrl = zlbConfig.alipaySsoUrl;
  124. // } else if (platformEnv.bIsDtDreamApp) {
  125. // console.log("浙里办环境单点登录");
  126. // ssoUrl = zlbConfig.zlbSsoUrl;
  127. // } else {
  128. // //为了h5测试
  129. // ssoUrl = zlbConfig.zlbSsoUrl;
  130. // }
  131. // if (params.code) {
  132. // ssoUrl += `&goto=${window.location.href.split("#")[0]}`;
  133. // }
  134. // console.log(ssoUrl);
  135. // window.location.replace(ssoUrl);
  136. // },
  137. // login() {
  138. // console.log("应用所处地址", window.location.href);
  139. // console.log("useragent", window.navigator.userAgent.toLowerCase());
  140. // const platformEnv = getPlatformEnv();
  141. // const params = this.getQuery(window.location.search);
  142. // if (params.qjw_debug) {
  143. // localStorage.setItem("debug", "true");
  144. // } else {
  145. // localStorage.setItem("debug", "false");
  146. // }
  147. // if (!params.ticket && !platformEnv.bIsWxMini) {
  148. // this.ssoLogin();
  149. // } else {
  150. // app.globalData.isLogin = true;
  151. // console.log(
  152. // "登录成功后回调地址和参数解析:",
  153. // window.location.href,
  154. // params
  155. // );
  156. // // 跳转回来的参数解析
  157. // if (params.sp) {
  158. // console.error("sp", params.sp);
  159. // const spParams = this.getQuery(decodeURIComponent(params.sp));
  160. // console.error("spParams", spParams);
  161. // app.globalData.options = {
  162. // code: spParams.code,
  163. // };
  164. // }
  165. // //门牌code直接在链接上的话,说明从微信小程序过来
  166. // if (params.code) {
  167. // console.log("应该为微信环境,链接地址:", window.location.href);
  168. // console.error("code:", params.code);
  169. // app.globalData.options = {
  170. // code: params.code,
  171. // };
  172. // }
  173. // let ticket = "";
  174. // //浙里办微信是获取ticketId
  175. // if (platformEnv.bIsWxMini) {
  176. // ticket = params.ticketId;
  177. // } else {
  178. // ticket = params.ticket;
  179. // }
  180. // console.log("获取的ticket", ticket);
  181. // this.getSsoUserInfo(ticket);
  182. // }
  183. // },
  184. // async getSsoUserInfo(ticket) {
  185. // let res = "";
  186. // try {
  187. // res = await getSsoUserInfo({ ticketId: ticket });
  188. // } catch (err) {
  189. // uni.setStorageSync("testErr", err);
  190. // if (uni.getStorageSync("errNum")) {
  191. // let errNum = Number(uni.getStorageSync("errNum"));
  192. // if (errNum + 1 < 3) {
  193. // uni.setStorageSync("errNum", errNum + 1);
  194. // } else {
  195. // uni.removeStorageSync("errNum");
  196. // return;
  197. // }
  198. // } else {
  199. // uni.setStorageSync("errNum", 1);
  200. // }
  201. // this.ssoLogin();
  202. // }
  203. // const userInfo = res.data;
  204. // // console.log("单点登录后用户信息", userInfo);
  205. // storageUserInfo({
  206. // nickName: userInfo.name,
  207. // avatarUrl: userInfo.headPicture,
  208. // phoneNumber: userInfo.phoneWx,
  209. // phoneWx: userInfo.phoneWx,
  210. // username: userInfo.name,
  211. // openId: userInfo.userIdZlb,
  212. // uuid: userInfo.uuid,
  213. // });
  214. // app.globalData.openid = userInfo.uuid;
  215. //
  216. // // 开始埋点上报
  217. // this.startTrack();
  218. // history.pushState(null, null, document.URL);
  219. // uni.removeStorageSync("errNum");
  220. // if (app.globalData.options.code) {
  221. // uni.switchTab({
  222. // url: "/pages/home/home",
  223. // });
  224. // } else {
  225. // if (
  226. // userInfo.doorplateCount
  227. // ) {
  228. // uni.switchTab({
  229. // url: "/pages/home/home",
  230. // });
  231. // } else {
  232. // uni.reLaunch({
  233. // url: "/subPages/pages/scanCode/scanCode",
  234. // });
  235. // }
  236. // }
  237. // },
  238. // startTrack() {
  239. // app.globalData.trackIns = new Track();
  240. // },
  241. // getQuery(url) {
  242. // const str = url.substr(url.indexOf("?") + 1);
  243. // const arr = str.split("&");
  244. // const result = {};
  245. // for (let i = 0; i < arr.length; i++) {
  246. // const item = arr[i].split("=");
  247. // result[item[0]] = item[1];
  248. // }
  249. // return result;
  250. // },
  251. /* 获取用户信息,免登 */
  252. async handleLogin(){
  253. const res = await dd.getAuthCode({
  254. corpId: '50329019'
  255. })
  256. if(res) {
  257. try{
  258. const exemptionRes = await exemption({
  259. code: res.code
  260. })
  261. if(exemptionRes.code === 0) {
  262. console.log('用户信息',exemptionRes.data)
  263. storageUserInfo({
  264. ...exemptionRes.data.userInfo,
  265. nickName: exemptionRes.data.userInfo.realName,
  266. avatarUrl: exemptionRes.data.userInfo.headPicture,
  267. phoneNumber: exemptionRes.data.userInfo.phoneWx,
  268. phoneWx: exemptionRes.data.userInfo.phoneWx,
  269. username: exemptionRes.data.userInfo.username,
  270. openId: exemptionRes.data.userInfo.id,
  271. uuid: exemptionRes.data.userInfo.id,
  272. });
  273. app.globalData.openid = exemptionRes.data.userInfo.id;
  274. uni.reLaunch({
  275. url: "/pages/home/home",
  276. });
  277. }else {
  278. this.$toast('获取用户信息失败')
  279. this.noAuth = true
  280. this.noAuthDesc = exemptionRes.msg
  281. }
  282. }catch (e) {
  283. this.noAuth = true
  284. this.noAuthDesc = "当前用户暂无权限"
  285. console.log('error',e)
  286. }
  287. }
  288. }
  289. },
  290. };
  291. </script>
  292. <style scoped></style>