threethousanddream 1 månad sedan
förälder
incheckning
8e15401507
6 ändrade filer med 155 tillägg och 65 borttagningar
  1. 15 12
      App.vue
  2. 27 9
      common/api.js
  3. 6 2
      pages/detail/app.vue
  4. 5 2
      pages/detail/bigdata.vue
  5. 85 40
      template.h5.html
  6. 17 0
      util/index.js

+ 15 - 12
App.vue

@@ -1,19 +1,22 @@
 <script>
 import Cookies from 'js-cookie'
+import {setToken} from '@/util'
 export default {
   onLaunch: function () {
-    uni.$u.http.get('/api/blade-token/currentUser').then(res => {
-      let {instType} = res.detail
-      let isSingle = instType === 1
-      this.$store.commit('setUser', {isSingle})
-      const Yxtoken = Cookies.get('congress')
-      const redirect = window.location.href;
-      if (Yxtoken) {
-        uni.redirectTo({url: isSingle ? '/pages/home/me' : '/pages/home/home'});
-      } else {
-        // 跳转到iam 用户端登陆
-        window.location.href = `${window._CONFIG.VUE_APP_BASE_URLS}/account/#/login?redirect=${redirect}`;
-      }
+    setToken().then(() => {
+      uni.$u.http.get('/api/blade-token/currentUser').then(res => {
+        let {instType} = res.detail
+        let isSingle = instType === 1
+        this.$store.commit('setUser', {isSingle})
+        const Yxtoken = Cookies.get('congress')
+        const redirect = window.location.href;
+        if (Yxtoken) {
+          uni.redirectTo({url: isSingle ? '/pages/home/me' : '/pages/home/home'});
+        } else {
+          // 跳转到iam 用户端登陆
+          window.location.href = `${window._CONFIG.VUE_APP_BASE_URLS}/account/#/login?redirect=${redirect}`;
+        }
+      })
     })
   },
   onShow: function () {

+ 27 - 9
common/api.js

@@ -1,18 +1,36 @@
+import {setToken} from "@/util";
 const {http} = uni.$u
-
+const request = ({url, params = {}, method = 'get'}) => new Promise((resolve, reject) => {
+  setToken().then(() => {
+    if (method === 'get') {
+      http.get(url, {params}).then(res => {
+        resolve(res)
+      }).catch(err => {
+        reject(err)
+      })
+    }
+    if (method === 'post') {
+      http.post(url, params).then(res => {
+        resolve(res)
+      }).catch(err => {
+        reject(err)
+      })
+    }
+  })
+})
 // 获取大屏列表
-export const bigdataList = (params = {}) => http.get('/bi-api/visual/data/list/waterfall', {params})
+export const bigdataList = params => request({url: '/bi-api/visual/data/list/waterfall', params})
 // 获取报表列表
-export const reportList = (params = {}) => http.get('/bi-api/visual/selfReport/list/waterfall', {params})
+export const reportList = params => request({url: '/bi-api/visual/selfReport/list/waterfall', params})
 // 获取分类列表
-export const classifyList = () => http.get('/bi-api/visual/classify/list')
+export const classifyList = () => request({url: '/bi-api/visual/classify/list',})
 // 收藏/取消
-export const reportClassList = () => http.get('/bi-api/visual/self/report/list')
+export const reportClassList = () => request({url: '/bi-api/visual/self/report/list',})
 // 系统应用列表
-export const systemAppPage = params => http.get('/bi-api/microApp/page', {params})
+export const systemAppPage = params => request({url: '/bi-api/microApp/page', params})
 // 我的应用列表
-export const mineAppPage = params => http.get('/bi-api/microApp/myPage', {params})
+export const mineAppPage = params => request({url: '/bi-api/microApp/myPage', params})
 // 分享大屏列表
-export const getShareList = params => http.get('/bi-api/visual/data/share/page', {params});
+export const getShareList = params => request({url: '/bi-api/visual/data/share/page', params})
 // 获取大屏访问量
-export const getPv = data => http.post('/bi-api/visual/data/visualViewCount', data);
+export const getPv = params => request({url: '/bi-api/visual/data/visualViewCount', params, method: 'post'})

+ 6 - 2
pages/detail/app.vue

@@ -6,17 +6,21 @@
 </template>
 <script>
 import Cookies from 'js-cookie'
+import {setToken} from "@/util";
 export default {
   data() {
     return {
       title: '详情',
       url: '',
-      token: Cookies.get('congress')
     }
   },
   onLoad(options) {
     this.title = options.title
-    this.url = `${window._CONFIG.APP_READY}?path=miniapp&appid=${options.id}&token=${this.token}#/newbi/auth`
+    setToken().then(() => {
+      let token = Cookies.get('congress')
+      this.url = `${window._CONFIG.APP_READY}?path=miniapp&appid=${options.id}&token=${token}#/newbi/auth`
+    })
+
   }
 }
 </script>

+ 5 - 2
pages/detail/bigdata.vue

@@ -6,17 +6,20 @@
 </template>
 <script>
 import Cookies from 'js-cookie'
+import {setToken} from "@/util";
 export default {
   data() {
     return {
       title: '详情',
       url: '',
-      token: Cookies.get('congress')
     }
   },
   onLoad(options) {
     this.title = options.title
-    this.url = `${window._CONFIG.APP_READY}?token=${this.token}#/newbi/fullscreen/${options.id}`
+    setToken().then(() => {
+      let token = Cookies.get('congress')
+      this.url = `${window._CONFIG.APP_READY}?token=${token}#/newbi/fullscreen/${options.id}`
+    })
   }
 }
 </script>

+ 85 - 40
template.h5.html

@@ -1,43 +1,88 @@
 <!DOCTYPE html>
 <html lang="zh-CN">
-	<head>
-		<meta charset="utf-8">
-		<meta http-equiv="X-UA-Compatible" content="IE=edge">
-		<link rel="shortcut icon" type="image/x-icon" href="/static/img/favicon.ico">
-		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
-		<title>
-			<%= htmlWebpackPlugin.options.title %>
-		</title>
-        <script src="/static/common/js/config.js"></script>
-		<!-- 正式发布的时候使用,开发期间不启用。↓ -->
-        <script src="/static/common/js/touch-emulator.js"></script>
-		<script>
-            TouchEmulator();
-		</script>
-        <style>
-            ::-webkit-scrollbar{
-                display: none;
-            }
-        </style>
-        <!-- 正式发布的时候使用,开发期间不启用。↑ -->
-		<script>
-			document.addEventListener('DOMContentLoaded', function() {
-				document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
-			})
-		</script>
-		<link rel="stylesheet" href="<%= BASE_URL %>static/index.css" />
-	</head>
-	<body>
-		<!-- 该文件为 H5 平台的模板 HTML,并非应用入口。 -->
-		<!-- 请勿在此文件编写页面代码或直接运行此文件。 -->
-		<!-- 详见文档:https://uniapp.dcloud.io/collocation/manifest?id=h5-template -->
-		<noscript>
-			<strong>本站点必须要开启JavaScript才能运行</strong>
-		</noscript>
-		<div id="app"></div>
-		<!-- built files will be auto injected -->
-		<script>
-			/*BAIDU_STAT*/
-		</script>
-	</body>
+<head>
+  <meta charset="utf-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <link rel="shortcut icon" type="image/x-icon" href="/static/img/favicon.ico">
+  <meta name="viewport"
+        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
+  <title>
+    <%= htmlWebpackPlugin.options.title %>
+  </title>
+  <script src="/static/common/js/config.js"></script>
+  <!-- 正式发布的时候使用,开发期间不启用。↓ -->
+  <script src="/static/common/js/touch-emulator.js"></script>
+  <script>
+    TouchEmulator();
+  </script>
+  <style>
+    ::-webkit-scrollbar {
+      display: none;
+    }
+  </style>
+  <!-- 正式发布的时候使用,开发期间不启用。↑ -->
+  <script>
+    document.addEventListener('DOMContentLoaded', function () {
+      document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
+    })
+    var u = navigator.userAgent;
+    var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android
+    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios
+    function setupWebViewJsBridge(params) {
+      if (window.WKWebViewJavascriptBridge) {
+        return params(window.WKWebViewJavascriptBridge);
+      }
+      if (window.WKWVJBCallbacks) {
+        window.WKWVJBCallbacks.push(params);
+      } else {
+        window.WKWVJBCallbacks = [params];
+      }
+      if (isAndroid) {
+        if (!window.InjectJavascript) {
+          window.alert("ERROR: window.InjectJavascript if null!");
+          return;
+        }
+        window.InjectJavascript.init();
+      } else if (isiOS) {
+        window.webkit && window.webkit.messageHandlers.h5ToApp.postMessage(params); // 给 ios 传参
+      }
+    }
+    function appToH5(data) {
+      let obj = JSON.parse(data)
+      for (const key in obj) {
+        if (obj.hasOwnProperty(key)) {
+          window[key] = obj[key];
+        }
+      }
+    }
+    function insideH5ToApp(params) {
+      setupWebViewJsBridge(isiOS ? JSON.stringify(params) : function (bridge) {
+        bridge.callHandler("h5ToApp", {key: params.key}, function (data) {
+          typeof window[params.void] === 'function' && window[params.void](data)
+        })
+      })
+    }
+    isAndroid && setupWebViewJsBridge(function (bridge) {
+      bridge.registerHandler("appToH5", function (data, callback) {
+        appToH5(JSON.stringify(data));
+      })
+    });
+    window.insideH5ToApp = insideH5ToApp; // 自己调用
+    window.appToH5 = appToH5;
+  </script>
+  <link rel="stylesheet" href="<%= BASE_URL %>static/index.css"/>
+</head>
+<body>
+<!-- 该文件为 H5 平台的模板 HTML,并非应用入口。 -->
+<!-- 请勿在此文件编写页面代码或直接运行此文件。 -->
+<!-- 详见文档:https://uniapp.dcloud.io/collocation/manifest?id=h5-template -->
+<noscript>
+  <strong>本站点必须要开启JavaScript才能运行</strong>
+</noscript>
+<div id="app"></div>
+<!-- built files will be auto injected -->
+<script>
+  /*BAIDU_STAT*/
+</script>
+</body>
 </html>

+ 17 - 0
util/index.js

@@ -1,3 +1,4 @@
+import Cookies from 'js-cookie'
 export function arrayToTree(list, {parentId = parentId, id = id}) {
   let parents = list.filter(i => !i[parentId])
   list.forEach(item => {
@@ -5,4 +6,20 @@ export function arrayToTree(list, {parentId = parentId, id = id}) {
     if (children.length) item.children = children
   })
   return parents
+}
+export function setToken() {
+  return new Promise((resolve, reject) => {
+    if (!Cookies.get('congress')) {
+      window.insideH5ToApp('userInfo', function (obj) {
+        window.alert(obj)
+        if (typeof obj === 'string') obj = JSON.parse(obj)
+        let {token, userId} = obj
+        window.alert(token)
+        Cookies.set('congress', token)
+        resolve()
+      })
+    } else {
+      resolve()
+    }
+  })
 }