Commit 9f412baf authored by ly's avatar ly

initinit

parent e7fbda84
No preview for this file type
// 把方法修改成Promise函数
export const convertPromise = function (FnName, params = {}) {
return new Promise((resolve, reject) => {
uni[FnName]({
...params,
success: function (res) {
return resolve(res)
},
fail: function (err) {
console.log(err, `处理${FnName}方法信息报错`)
return reject(err)
},
complete: function (res) {
//console.log(res,`处理${FnName}方法信息完成`)
}
})
});
}
// 初始化请求头的device参数信息
export const initHeaderDevice = function () {
const common = {
appName: 'DDH',
appSourceId: "1",
token: "c695fa285b9dc46a", // 设备令牌(device_token) 设备udid
idfa: "", // IOS设备则为:IDFA 广告标识
imei: "", //安卓设备为:imei
mac: "", // mac
wifiMac: "", // wifimac
clientIp: "",
carrierOperator: 'OperatorName', //运营商
pushType: "1", //设备push接入类型(1. 小米PUSH,2. 极光PUSH)
electricQuantity: "", //电量
totalStorage: "", //存储总空间
availableStorage: "" //可用存储空间
};
const deviceInfo = uni.getStorageSync('m-device-info')
const networkInfo = uni.getStorageSync('m-network-info')
// const locationInfo = uni.getStorageSync('m-location-info')
const loadUuid = uni.getStorageSync('m-load-udid')
let device = {};
if (deviceInfo) {
device = Object.assign(device, common, JSON.parse(deviceInfo))
}
if (networkInfo) {
device = Object.assign(device, common, JSON.parse(networkInfo))
}
if (locationInfo) {
device = Object.assign(device, common, JSON.parse(locationInfo))
}
if(loadUuid){
device = Object.assign(device, common, JSON.parse(loadUuid))
}
if (deviceInfo && networkInfo && loadUuid) {
const headerDeviceInfo = {
...JSON.parse(deviceInfo),
...JSON.parse(networkInfo),
...JSON.parse(loadUuid),
...common
}
// 存储所有请求的头部信息
uni.setStorage({
key: 'm-header-device',
data: JSON.stringify(headerDeviceInfo),
success: function () {
console.log('m-header-device存储成功4');
}
});
return headerDeviceInfo
}
return device
}
// 把方法修改成Promise函数
export const convertPromise = function (FnName, params = {}) {
return new Promise((resolve, reject) => {
uni[FnName]({
...params,
success: function (res) {
return resolve(res)
},
fail: function (err) {
console.log(err, `处理${FnName}方法信息报错`)
return reject(err)
},
complete: function (res) {
//console.log(res,`处理${FnName}方法信息完成`)
}
})
});
}
// 初始化请求头的device参数信息
export const initHeaderDevice = function () {
const common = {
appName: 'DDH',
appSourceId: "1",
token: "c695fa285b9dc46a", // 设备令牌(device_token) 设备udid
idfa: "", // IOS设备则为:IDFA 广告标识
imei: "", //安卓设备为:imei
mac: "", // mac
wifiMac: "", // wifimac
clientIp: "",
carrierOperator: 'OperatorName', //运营商
pushType: "1", //设备push接入类型(1. 小米PUSH,2. 极光PUSH)
electricQuantity: "", //电量
totalStorage: "", //存储总空间
availableStorage: "" //可用存储空间
};
const deviceInfo = uni.getStorageSync('m-device-info')
const networkInfo = uni.getStorageSync('m-network-info')
const locationInfo = uni.getStorageSync('m-location-info')
const loadUuid = uni.getStorageSync('m-load-udid')
let device = {};
if (deviceInfo) {
device = Object.assign(device, common, JSON.parse(deviceInfo))
}
if (networkInfo) {
device = Object.assign(device, common, JSON.parse(networkInfo))
}
if (locationInfo) {
device = Object.assign(device, common, JSON.parse(locationInfo))
}
if(loadUuid){
device = Object.assign(device, common, JSON.parse(loadUuid))
}
if (deviceInfo && networkInfo && loadUuid) {
const headerDeviceInfo = {
...JSON.parse(deviceInfo),
...JSON.parse(networkInfo),
...JSON.parse(loadUuid),
...common
}
// 存储所有请求的头部信息
uni.setStorage({
key: 'm-header-device',
data: JSON.stringify(headerDeviceInfo),
success: function () {
console.log('m-header-device存储成功4');
}
});
return headerDeviceInfo
}
return device
}
import {initHeaderDevice} from './header.js'
const request=async(url,type,data)=>{
const baseUrl='http://112.124.25.186:8089' //测试
// const baseUrl='https://api.taimedias.com'//线上
// 这里确保一定是可以获取得到的
const headerDevice = uni.getStorageSync('m-header-device')
let rd = null;
if (headerDevice) {
rd = headerDevice
} else {
const common = initHeaderDevice()
rd = JSON.stringify(common)
}
// console.log(rd,'rd')
return new Promise((resolve,reject)=>{
const token=uni.getStorageSync('token')
uni.request({
url: baseUrl+url,
method:type,
data: {
...data
},
header: {
Accept: "application/json;charset=UTF-8",
"Content-Type": "application/json;charset=UTF-8",
device:rd,
Authorization:token,
Author:token,
},
success: (res) => {
const {data, statusCode} = res;
if (statusCode === 200) {
if (data.success==true) {
return resolve(data)
} else {
if(data.code=='403'){
console.log(res,'402');
uni.showToast({
title: data.message,
icon: "none",
duration: 2000
})
uni.removeStorageSync('token')
// this.Go('uni:/pages/login/login')
}else{
uni.showToast({
title: data.message,
icon: "none",
duration: 2000
})
return false
}
}
} else {
console.log(res.errMsg,'!200');
return reject({
data,
message: res.errMsg
})
}
},
fail:(err)=> {
console.log(err,954)
return uni.showToast({
icon:'loading',
title:'请求失败'
})
reject(err)
}
});
})
}
export default request;
\ No newline at end of file
import {initHeaderDevice} from './header.js'
const request=async(url,type,data)=>{
// const baseUrl='http://112.124.25.186:8089' //测试
const baseUrl='http://api.yyhock.com'//线上
// 这里确保一定是可以获取得到的
const headerDevice = uni.getStorageSync('m-header-device')
let rd = null;
if (headerDevice) {
rd = headerDevice
} else {
const common = initHeaderDevice()
rd = JSON.stringify(common)
}
// console.log(rd,'rd')
return new Promise((resolve,reject)=>{
const token=uni.getStorageSync('token')
uni.request({
url: baseUrl+url,
method:type,
data: {
...data
},
header: {
Accept: "application/json;charset=UTF-8",
"Content-Type": "application/json;charset=UTF-8",
device:rd,
Authorization:token,
Author:token,
},
success: (res) => {
const {data, statusCode} = res;
if (statusCode === 200) {
if (data.success==true) {
return resolve(data)
} else {
if(data.code=='403'){
console.log(res,'402');
uni.showToast({
title: data.message,
icon: "none",
duration: 2000
})
uni.removeStorageSync('token')
// this.Go('uni:/pages/login/login')
}else{
uni.showToast({
title: data.message,
icon: "none",
duration: 2000
})
return false
}
}
} else {
console.log(res.errMsg,'!200');
return reject({
data,
message: res.errMsg
})
}
},
fail:(err)=> {
console.log(err,954)
return uni.showToast({
icon:'loading',
title:'请求失败'
})
reject(err)
}
});
})
}
export default request;
\ No newline at end of file
<script>
import { convertPromise } from './utils/header.js'
import { convertPromise ,initHeaderInfo} from './utils/header.js'
import Permission from '@/js_sdk/wa-permission/permission'
import { SelectLocation } from "./utils/authPerission";
import silentlyAppUpdate from '@/pages/app-update/js-sdk/silentlyAppUpdate'
......@@ -12,23 +12,27 @@
this.loadNetwork();
this.loadLocation();
this.loadUuid()
// const isAgree = uni.getStorageSync('m-agreement')
// console.log(isAgree,'isAgree1')
}
plus.screen.lockOrientation("portrait-primary")
console.log('App Launch')
/*** tabbar*/
this.switchShowTabbar()
// 重点是以下: 一定要监听后台恢复 !一定要
// plus.globalEvent.addEventListener('newintent', (e) => {
// // this.checkArguments() // 检测启动参数
// console.log(e,'333')
// if (plus.runtime.isAgreePrivacy()) {
// console.log(e,'444')
// initHeaderInfo()
// }
// })
//app更新版本
// silentlyAppUpdate()
// if (plus.runtime.isAgreePrivacy()) {
// initHeaderInfo()
// silentlyAppUpdate()
// }
silentlyAppUpdate()
if (plus.runtime.isAgreePrivacy()) {
// setDevice()
silentlyAppUpdate()
}
plus.screen.lockOrientation("portrait-primary")
console.log('App Launch')
},
methods:{
//tab的信息
......@@ -177,15 +181,8 @@
}
},
onShow: function() {
console.log('App Show')
/*** tabbar*/
this.switchShowTabbar()
// 版本更新
silentlyAppUpdate()
if (plus.runtime.isAgreePrivacy()) {
// setDevice()
silentlyAppUpdate()
}
console.log(2,'App Show')
},
onHide: function() {
......
......@@ -378,8 +378,11 @@
key: "m-agreement",
data: 'true',
success: function () {
console.log('m-agreement成功')
}
})
const headerDevice = uni.getStorageSync('m-header-device')
console.log(headerDevice,'headerDevice')
if (this.downloading) {
console.log(1,'9')
uni.showModal({
......
......@@ -22,7 +22,7 @@ export default function checkVersion() {
if (res.success==true) {
let response = res.result.data;
console.log(response,'appVersion')
let result = {};
result.versionCode = response.version;
result.versionName = response.versionName;
......
......@@ -72,6 +72,7 @@
</template>
<script>
import {switchShowTabbar} from '../../utils/deviceInfo.js'
import silentlyAppUpdate from '@/pages/app-update/js-sdk/silentlyAppUpdate'
export default {
data() {
......@@ -264,6 +265,7 @@
this.token=token
this.init()
this.searchGood()
// switchShowTabbar()
}
}
</script>
......
......@@ -171,12 +171,8 @@
const { deviceId}=userInfo
uni.setStorageSync('deviceId',deviceId)
}
uni.setStorageSync('mobileCall',self.mobile)
uni.setStorageSync('token',token)
// self.loginNocheck()
uni.navigateBack({
delta: 1
})
self.loginNocheck()
}).catch(err=>{
console.log(err,'请求出错')
})
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -8974,7 +8974,7 @@ if(false) {}
var ___CSS_LOADER_API_IMPORT___ = __webpack_require__(/*! ../../../../../Applications/HBuilderX 2.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/css-loader/dist/runtime/api.js */ 10);
exports = ___CSS_LOADER_API_IMPORT___(false);
// Module
exports.push([module.i, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n/*每个页面公共css */\n", ""]);
exports.push([module.i, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n/*每个页面公共css */\n", ""]);
// Exports
module.exports = exports;
......@@ -8,6 +8,7 @@
import { convertPromise } from '../utils/header.js'
import Permission from '../js_sdk/wa-permission/permission.js'
import { SelectLocation } from "../utils/authPerission.js";
// import { getAppVersion } from "@/api/api.js";
// 获取common当中的设备信息
export const loadDevice=function() {
const that = this
......
......@@ -37,7 +37,7 @@ export const initHeaderDevice = function () {
const deviceInfo = uni.getStorageSync('m-device-info')
const networkInfo = uni.getStorageSync('m-network-info')
// const locationInfo = uni.getStorageSync('m-location-info')
const locationInfo = uni.getStorageSync('m-location-info')
const loadUuid = uni.getStorageSync('m-load-udid')
let device = {};
......@@ -59,6 +59,7 @@ export const initHeaderDevice = function () {
const headerDeviceInfo = {
...JSON.parse(deviceInfo),
...JSON.parse(networkInfo),
// ...JSON.parse(locationInfo),
...JSON.parse(loadUuid),
...common
}
......
import {initHeaderDevice} from './header.js'
import {initHeaderDevice,initHeaderInfo} from './header.js'
import api from '@/config/api.js'
const request=async(url,type,data)=>{
const baseUrl=api.common
// 这里确保一定是可以获取得到的
const headerDevice = uni.getStorageSync('m-header-device')
let rd = null;
const deviceInfo = uni.getStorageSync('m-device-info')
let rd=null
console.log(deviceInfo,'8888')
if (headerDevice) {
rd = headerDevice
console.log(rd,'rd1')
} else {
const common = initHeaderDevice()
rd = JSON.stringify(common)
console.log(rd,'rd2')
}
// console.log(baseUrl,'rd')
console.log(rd,'rd3')
return new Promise((resolve,reject)=>{
const token=uni.getStorageSync('token')
const tokenFinance=uni.getStorageSync('tokenFinance')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment