12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import { createRouter, createWebHashHistory, Router } from 'vue-router';
- import { useCookies } from '@vueuse/integrations/useCookies';
- const current = window.navigator.language || window.navigator.userLanguage || null;
- let mytitle = '用户反馈';
- if (current && !/^zh/.test(current)) {
- mytitle = 'Feedback';
- }
- import routes from './routes';
- const router: Router = createRouter({
- history: createWebHashHistory(),
- routes: routes,
- });
- router.beforeEach(async (_to, _from, next) => {
- console.log('_to', _to);
- const wxOpenId = useCookies().get('wxOpenId');
- if (_to.name == 'feedback' || _to.name == 'feedbacksuccess') {
- document.title = mytitle;
- } else {
- document.title = '四维时代售后';
- }
- if (wxOpenId || _to.name == 'feedback' || _to.name == 'feedbacksuccess' || getUrlKey('code')) {
- next();
- } else {
- getCodeApi(123);
- }
- });
- function getUrlKey(name) {
- //获取url 参数
- return (
- decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20')) ||
- null
- );
- }
- function getCodeApi(state) {
- //获取code
- console.log('getCodeApi');
- const urlNow = encodeURIComponent(window.location.href);
- const scope = 'snsapi_base'; //snsapi_userinfo //静默授权 用户无感知
- const appid = 'wxac3d59ea82d9b82a';
- const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`;
- window.location.replace(url);
- }
- export default router;
|