| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- export default {
- mounted() {
- this.getDeviceType()
- },
- data() {
- return {
- // 设备类型pc,ios,android
- deviceType: 'pc'
- }
- },
- methods: {
- /**
- * 设备判断
- */
- getDeviceType() {
- const strCookie = document.cookie;
- //将多cookie切割为多个名/值对
- const arrCookie = strCookie.split("; ");
- let xAPP = "";
- //遍历cookie数组,处理每个cookie对
- for(let i=0; i<arrCookie.length; i++){
- const arr = arrCookie[i].split("=");
- //找到名称为x_app的cookie,并返回它的值
- if ("x_app" === arr[0]){
- xAPP = arr[1];
- break;
- }
- }
- if (xAPP.toLowerCase().indexOf('ios') !== -1) { //判断iPhone|iPad|iPod|iOS APP
- this.deviceType = 'ios';
- } else if (xAPP.toLowerCase().indexOf('android') !== -1) { //判断Android app
- this.deviceType = 'android';
- } else { // pc OR H5 todo 判断UA,精准识别是H5还是PC
- this.deviceType = 'pc';
- }
- },
- /**
- * get sign for iOS
- */
- getSign() {
- const sign = {
- // x_app: 'ios 4.6.0',
- x_nonce_str: '1558105441627',
- x_signature: 'h5'
- };
- if (document && document.cookie) {
- document.cookie.split(/; ?/).forEach(item => {
- if (item) {
- const it = item.split('=');
- if (it[0] === 'x_app' || it[0] === 'x_access_token') {
- sign[it[0]] = it[1];
- }
- }
- });
- }
- return sign;
- },
- /**
- * get cookie
- */
- getCookie() {
- const cookie = {};
- if (document && document.cookie) {
- document.cookie.split(/; ?/).forEach(item => {
- if (item) {
- const it = item.split('=');
- cookie[it[0]] = it[1];
- }
- });
- }
- return cookie;
- }
- }
- }
|