浙里办(单点登录、适老化、埋点、mgop网关依赖)
1.单点登录
2. 埋点
在public文件夹里面index.html中接入
<script type="text/javascript" src="https://assets.zjzwfw.gov.cn/assets/zwlog/1.0.0/zwlog.js"></script>
进行埋点操作
const zwlog = new ZwLog({
_user_id: '',
_user_nick: ''
})
zwlog.onReady(() => {
zwlog.sendPV({
miniAppId: 'IRS服务侧应用appid',
Page_duration: '用户从进入到离开当前页面的时长',
t2: '页面启动到加载完成的时间',
t0: '页面启动到页面响应完成的时间',
log_status: 'IRS服务侧应用appid'
});
zwlog.record('yourTrackerEventCode', 'CLK', {
Test1: '测试参数 1',
});
let { metaInfo } = zwlog;
})
3. 适老化
适老化是浙里办上架h5硬性要求的,必须做。 我这边使用vuex存放一个全局变量,在首页判断当前系统的uityle,然后设置vuex中的uistyle变量的值,根据值来改变class类名
export default new Vuex.Store({
state: {
uiStyle: 'normal'
},
mutations: {
setUiStyle (state, value) {
state.uiStyle = value
}
},
getters: {
getuiStyle: state => {
return state.uiStyle
}
}
})
import { mapMutations } from 'vuex';
mounted(){
let _self = this;
ZWJSBridge.getUiStyle().then(res => {
if(res.uiStyle == 'elder'){
_self.setUiStyle('elder')
setUiStyle('适老模式');
}else{
_self.setUiStyle('normal')
setUiStyle('标准模式');
}
}).catch(err => {
console.log('getUiStyle--err', err)
})
},
methods: {
...mapMutations(['setUiStyle']),
}
<template>
<div :class="[uiStyle == 'normal' ? 'pages-normal': 'pages-elder']">
....
</div>
</template>
<script>
import { mapGetters } from "vuex";
export default {
computed: {
...mapGetters({
uiStyle: 'getuiStyle'
})
}
}
</script>
<style lang="scss" scoped>
.pages-normal{...}
.pages-elder{...}
</style>
4. mgop网关依赖
浙里办必须使用@aligov/jssdk-mgop进行请求;
npm i --save @aligov/jssdk-mgop@3.0.0
封装@aligov/jssdk-mgop请求
import { mgop } from '@aligov/jssdk-mgop'
const request = (payload) => {
let xtoken = '登录后获取的xtoken'
return new Promise((resolve, reject) => {
mgop({
api: 'mgop.zjxx.xhjf.' + payload.url,
host: 'https://mapi.zjzwfw.gov.cn/',
dataType: 'JSON',
type: payload.method,
appKey: 'appkey',
data: payload.method == 'post' ? payload.data : payload.params,
header: {'XToken': xtoken},
onSuccess: data => {
console.log('mgopRequest-----------------data', data)
resolve(data.data)
},
onFail: err => {
console.log('mgopRequest-----------------err', err)
reject(err.message)
}
})
})
}
export default request
5. ZWJSBridge的一些常用api
ZWJSBridge.getUserType({}).then(res => {
}).catch((error) => {
console.log('error', error);
});
ZWJSBridge.getUiStyle().then(res => {
if(res.uiStyle == 'elder'){
setUiStyle('适老模式');
}else{
setUiStyle('标准模式');
}
}).catch(err => {
console.log('getUiStyle--err', err)
})
ZWJSBridge.phoneCall({
corpId:'*******'
}).then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
ZWJSBridge.getLocation()
.then((result) => {
console.log(result);
...
}).catch((error) => {
console.log(error);
});
|