Commit 7db98cc51d3731bb283169032a1ebbcbbf468d67

Authored by fengwotao
2 parents e91427fb 3e274017

perf: 优化app

... ... @@ -11,6 +11,7 @@
11 11 data() {
12 12 return {
13 13 showConfiguration: '',
  14 + defauleConfigImage: 'https://dev.thingskit.com',
14 15 params: ''
15 16 };
16 17 },
... ... @@ -19,7 +20,7 @@
19 20 isConfiguration: true
20 21 });
21 22 if (e.configId !== null) {
22   - this.params = e.configId;
  23 + this.params = e.configurationHref;
23 24 this.requestUrl(this.params);
24 25 }
25 26 // 隐藏原生的tabbar
... ... @@ -58,8 +59,8 @@
58 59 });
59 60 const pathUrl = uni.getStorageSync('config');
60 61 const userInfo = uni.getStorageSync('userInfo')
61   - this.showConfiguration =
62   - `${pathUrl.baseURL}/?configurationId=${e}&userId=${userInfo.userId}&lightbox=1`
  62 + console.log(this.params)
  63 + this.showConfiguration = this.params
63 64 }
64 65 }
65 66 };
... ...
1 1 <template>
2   - <view class="configuation-page">
3   - <!-- 公共组件-每个页面必须引入 -->
4   - <public-module></public-module>
5   - <view class="configuation-header">
6   - <view class="header-gap"></view>
  2 + <view class="status-page">
  3 + <view style="margin-left:15rpx;background-color: #f8f9fa;position:fixed;top:0rpx;z-index: 99999;">
  4 + <view style="height:35rpx;background-color: #f8f9fa;"></view>
7 5 <view class="u-flex search-top">
8 6 <view class="search-main">
9 7 <u--input @change="inputChanged" prefixIcon="search" placeholder="请输入组态名称" border="surround"
... ... @@ -12,12 +10,14 @@
12 10 </view>
13 11 </view>
14 12 <view style="height:35rpx"></view>
  13 + <!-- 公共组件-每个页面必须引入 -->
  14 + <public-module></public-module>
15 15 <!-- 自带分页组件 -->
16 16 <mescroll-body ref="mescrollRef" :up="upOption" @init="mescrollInit" :down="downOption" @down="downCallback"
17 17 @up="upCallback">
18 18 <view class="configuation-container">
19 19 <view class="configuation-item">
20   - <view @click="openConfigDetail(item.id)" v-for="(item, index) in list" :key="index" class="item">
  20 + <view @click="openConfigDetail(item)" v-for="(item, index) in list" :key="index" class="item">
21 21 <image class="image" :src="item.icon || defaultConfigImage"></image>
22 22 <text class="name">{{ item.name }}</text>
23 23 </view>
... ... @@ -25,6 +25,7 @@
25 25 </view>
26 26 <mescroll-empty v-if="!list.length" />
27 27 </mescroll-body>
  28 + <!-- 自带分页组件 -->
28 29 <view style="height: 60rpx;"></view>
29 30 </view>
30 31 </template>
... ... @@ -32,12 +33,15 @@
32 33 <script>
33 34 import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
34 35 import api from '@/api/index.js'
  36 + import {
  37 + createScadaPageLink
  38 + } from './help';
35 39
36 40 export default {
37 41 mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
38 42 data() {
39 43 return {
40   - defaultConfigImage: '/static/test.png',
  44 + defaultConfigImage: '../../../static/test.png',
41 45 page: {
42 46 num: 0,
43 47 size: 10
... ... @@ -70,8 +74,9 @@
70 74 this.loadData(1, e);
71 75 },
72 76 openConfigDetail(e) {
  77 + const href = createScadaPageLink(e)
73 78 uni.navigateTo({
74   - url: 'configuration-detail?configId=' + e
  79 + url: 'configurationDetail?configurationHref=' + href
75 80 });
76 81 },
77 82 /*下拉刷新的回调 */
... ...
  1 +import config from '../../../config/baseUrl.js'
  2 +import {
  3 + atob,
  4 + btoa
  5 +} from './weapp.atob.js'
  6 +const getRandomString = () => Number(Math.random().toString().substring(2)).toString(36);
  7 +
  8 +export const ScadaModeEnum = {
  9 + PRIVATE_VIEW: 'PRIVATE_VIEW',
  10 + PUBLIC_VIEW: 'PUBLIC_VIEW',
  11 +}
  12 +
  13 +export const encode = (record) => {
  14 + let hash = JSON.stringify(record);
  15 + const mixinString = getRandomString()
  16 + .slice(0, 10)
  17 + .padEnd(10, getRandomString())
  18 + .split('')
  19 + .map((item) => (Math.random() > 0.5 ? item.toUpperCase() : item))
  20 + .join('');
  21 + hash = btoa(hash);
  22 + hash = hash.substring(0, 6) + mixinString + hash.substring(6);
  23 + hash = btoa(hash);
  24 + return hash;
  25 +};
  26 +
  27 +
  28 +export const createScadaPageLink = (
  29 + record,
  30 + mode = ScadaModeEnum.PRIVATE_VIEW,
  31 + open = false
  32 +) => {
  33 + const userInfo = uni.getStorageSync('userInfo')
  34 + const params = {
  35 + configurationId: record?.id,
  36 + organizationId: record?.organizationId,
  37 + mode: record?.viewType === ScadaModeEnum.PRIVATE_VIEW ? 'lightbox' : 'share',
  38 + platform: record?.platform,
  39 + userId: userInfo.userId
  40 + };
  41 +
  42 + if (record?.viewType === ScadaModeEnum.PUBLIC_VIEW) {
  43 + params.publicId = record.publicId;
  44 + }
  45 +
  46 + const hash = encode(params);
  47 +
  48 + const href = `${config.baseDrawioUrl}#${hash}`
  49 +
  50 + return href
  51 +};
\ No newline at end of file
... ...
  1 +var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  2 +var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
  3 +export const btoa = function(string) {
  4 + string = String(string);
  5 + var bitmap, a, b, c, result = "",
  6 + i = 0,
  7 + rest = string.length % 3;
  8 + for (; i < string.length;) {
  9 + if ((a = string.charCodeAt(i++)) > 255 ||
  10 + (b = string.charCodeAt(i++)) > 255 ||
  11 + (c = string.charCodeAt(i++)) > 255)
  12 + throw new TypeError(
  13 + "Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range."
  14 + );
  15 + bitmap = (a << 16) | (b << 8) | c;
  16 + result += b64.charAt(bitmap >> 18 & 63) + b64.charAt(bitmap >> 12 & 63) +
  17 + b64.charAt(bitmap >> 6 & 63) + b64.charAt(bitmap & 63);
  18 + }
  19 + return rest ? result.slice(0, rest - 3) + "===".substring(rest) : result;
  20 +};
  21 +
  22 +export const atob = function(string) {
  23 + string = String(string).replace(/[\t\n\f\r ]+/g, "");
  24 + if (!b64re.test(string))
  25 + throw new TypeError(
  26 + "Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
  27 + string += "==".slice(2 - (string.length & 3));
  28 + var bitmap, result = "",
  29 + r1, r2, i = 0;
  30 + for (; i < string.length;) {
  31 + bitmap = b64.indexOf(string.charAt(i++)) << 18 | b64.indexOf(string.charAt(i++)) << 12 |
  32 + (r1 = b64.indexOf(string.charAt(i++))) << 6 | (r2 = b64.indexOf(string.charAt(i++)));
  33 + result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255) :
  34 + r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255) :
  35 + String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255);
  36 + }
  37 + return result;
  38 +};
  39 +
  40 +function b64DecodeUnicode(str) {
  41 + return decodeURIComponent(exports.weAtob(str).replace(/(.)/g, function(p) {
  42 + var code = p.charCodeAt(0).toString(16).toUpperCase();
  43 + if (code.length < 2) {
  44 + code = "0" + code;
  45 + }
  46 + return "%" + code;
  47 + }));
  48 +}
  49 +
  50 +function base64_url_decode(str) {
  51 + var output = str.replace(/-/g, "+").replace(/_/g, "/");
  52 + switch (output.length % 4) {
  53 + case 0:
  54 + break;
  55 + case 2:
  56 + output += "==";
  57 + break;
  58 + case 3:
  59 + output += "=";
  60 + break;
  61 + default:
  62 + throw "Illegal base64url string!";
  63 + }
  64 + try {
  65 + return b64DecodeUnicode(output);
  66 + } catch (err) {
  67 + return exports.weAtob(output);
  68 + }
  69 +}
  70 +
  71 +function weappJwtDecode(token, options) {
  72 + if (typeof token !== "string") {
  73 + throw ("Invalid token specified");
  74 + }
  75 + options = options || {};
  76 + var pos = options.header === true ? 0 : 1;
  77 + try {
  78 + return JSON.parse(base64_url_decode(token.split(".")[pos]));
  79 + } catch (e) {
  80 + throw ("Invalid token specified: " + e.message);
  81 + }
  82 +}
\ No newline at end of file
... ...