App.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div id="app">
  3. <router-view />
  4. <theme-picker />
  5. </div>
  6. </template>
  7. <script>
  8. import ThemePicker from "@/components/ThemePicker";
  9. import { authToken } from "@/api/login";
  10. import { openAuth } from "dingtalk-design-libs/biz/openAuth";
  11. import { setToken } from "@/utils/auth";
  12. import * as dd from "dingtalk-jsapi"; // 在此引入
  13. export default {
  14. name: "App",
  15. components: { ThemePicker },
  16. created() {
  17. let that = this;
  18. // 判断是否是移动端
  19. let isMobileEnv = this.isMobile();
  20. // 储存
  21. this.$store.commit("app/SET_IS_MOBILE_ENV", isMobileEnv);
  22. // 取值-同步
  23. console.log("是否是移动端=", this.$store.state.app.isMobileEnv);
  24. if (dd.env.platform !== "notInDingTalk") {
  25. dd.ready(function () {
  26. // 钉钉免登录认证
  27. // dd.getAuthCode({
  28. // corpId: "ding4ab75ecd53106cde4ac5d6980864d335",
  29. // success: (res) => {
  30. // console.log("res=", res);
  31. // avoidLogin(res.code).then((res) => {
  32. // console.log("===avoidLogin_res=",res)
  33. // });
  34. // },
  35. // fail: (err) => {
  36. // console.log("err=", err);
  37. // },
  38. // complete: () => {},
  39. // });
  40. // 唤起授权
  41. openAuth({
  42. clientId: "dingwlimimzllguvqf8x", // 应用ID(唯一标识)
  43. corpId: "ding4ab75ecd53106cde4ac5d6980864d335", // 当前组织的corpId
  44. rpcScope: "Contact.User.Read", //通讯录
  45. fieldScope: "Contact.User.mobile", //手机号
  46. type: 0, // 0 标识授权个人信息;1 标识授权组织信息
  47. }).then((res) => {
  48. // 处理返回数据
  49. console.log("免登res=", res);
  50. authToken(res.result.authCode).then((res) => {
  51. let userInfo = res.sysUser;
  52. setToken(res.token);
  53. that.$store.commit("SET_TOKEN", res.token);
  54. console.log("----钉钉环境----");
  55. that.toTargetPage();
  56. // userInfo.nick
  57. // userInfo.mobile
  58. // userInfo.avatarUrl
  59. // openId unionId
  60. });
  61. });
  62. });
  63. }
  64. },
  65. metaInfo() {
  66. return {
  67. title:
  68. this.$store.state.settings.dynamicTitle &&
  69. this.$store.state.settings.title,
  70. titleTemplate: (title) => {
  71. return title
  72. ? `${title} - ${process.env.VUE_APP_TITLE}`
  73. : process.env.VUE_APP_TITLE;
  74. },
  75. };
  76. },
  77. methods: {
  78. //判断是否是移动端
  79. isMobile() {
  80. return (
  81. navigator.userAgent.match(
  82. /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
  83. ) !== null
  84. );
  85. },
  86. // 判断是否是移动端跳转
  87. toTargetPage() {
  88. let that = this;
  89. // 判断客户端环境
  90. let isMobileEnv = this.$store.state.app.isMobileEnv;
  91. console.log("app=====isMobileEnv=", isMobileEnv);
  92. if (isMobileEnv) {
  93. that.$router.replace({
  94. path: that.redirect || "/mobile/resume/index",
  95. });
  96. } else {
  97. that.$router.push({
  98. path: that.redirect || "/",
  99. query: { type: "admin", title: "智能简历" },
  100. });
  101. }
  102. },
  103. },
  104. };
  105. </script>
  106. <style scoped>
  107. #app .theme-picker {
  108. display: none;
  109. }
  110. </style>