1 Star 0 Fork 0

miaoxin/lxs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
App.vue 8.92 KB
一键复制 编辑 原始数据 按行查看 历史
miaoxin 提交于 2024-08-05 14:57 . 提交
<script>
import Vue from 'vue';
const api = require('./api/api.js');
const common = require('./common.js');
const elvutils = require('./utils/elvutils.js');
const cache = require('./utils/cache.js');
const ws = require('./api/ws.js');
//测试派生拉取合并--删除
export default {
globalData: {
//是否出现导航栏
globalshowNavbar: true,
// 传给guide的值
appletPoiId: '',
// id类型
appletCategoryId: '',
// openid
openid: '',
//设备号
deviceId: '',
tabCurrentIndex: 0, //poi列表当前选项
H5WebsockState: false
},
onLaunch: function() {
let that = this;
//是否是调试模式,调试模式输出日志
Vue.prototype.debug = true;
api.setAppIns(this);
ws.setAppIns(this);
Vue.prototype.api = api;
Vue.prototype.elvutils = elvutils;
Vue.prototype.cache = cache;
//从缓存中读取appid
this.globalData.openid = cache.get('openid') || null
//加载布局信息
this.globalData.deviceId = cache.get('deviceId') || elvutils.generateUUID()
// api.getPageLayout().then(result => {
// if (result.success) {
// uni.setStorageSync('pageLayout', result.data)
// }
// });
//加载appconfig
// api.getAppconfig().then(
// result => {
// if (result.success) {
// console.log(result.data, 'getAppconfig')
// cache.put('appconfig', result.data);
// }
// },
// err => {}
// );
uni.getSystemInfo({
success: function(e) {
// #ifndef MP
Vue.prototype.StatusBar = e.statusBarHeight;
if (e.platform == 'android') {
Vue.prototype.CustomBar = e.statusBarHeight + 40;
} else {
Vue.prototype.CustomBar = e.statusBarHeight + 45;
}
// #endif
// #ifdef MP-WEIXIN
Vue.prototype.StatusBar = e.statusBarHeight;
let custom = wx.getMenuButtonBoundingClientRect();
Vue.prototype.Custom = custom;
Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
// #endif
// #ifdef MP-ALIPAY
Vue.prototype.StatusBar = e.statusBarHeight;
Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
// #endif
//屏幕宽度
let screenWidth = e.screenWidth;
//屏幕高度
let screenHeight = e.screenHeight;
let pixelRatio = e.pixelRatio;
//根据屏幕宽度适配图片缩略图
if (screenWidth > 800) {
let imagestyle = {};
for (var i in api.imagestyle) {
imagestyle[i] = '';
}
//设置图片样式
Vue.prototype.imagestyle = imagestyle;
// Vue.prototype.imagestyle = {
// list200x160: '', //列表200x160
// list700x350: '', //列表750x350
// list400x300: '', //列表400x300
// contentimg:''
// };
} else {
Vue.prototype.imagestyle = api.imagestyle;
}
}
});
//判断用户是否登录
Vue.prototype.userIsLogin = function() {
return elvutils.userIsLogin();
};
//登录方法
Vue.prototype.login = function(resback) {
// #ifdef MP-WEIXIN
uni.navigateTo({
url: '/pages/mycenter/mp-login/index'
})
return;
// #endif
uni.navigateTo({
url: '/pages/users/index'
});
};
Vue.prototype.closeLoading = function(self) {
return self.$refs.comLoading.init()
};
Vue.prototype.redirectToError = function(self) {
uni.redirectTo({
url: '/pcom/pages/error/index'
})
};
Vue.prototype.setPageTitle = function(pageKey) {
var title = common.getUrlMap(pageKey);
if (!title) return;
uni.setNavigationBarTitle({
title: title
});
return title;
};
Vue.prototype.getPageTitle = function(pageKey) {
var title = common.getUrlMap(pageKey);
if (!title) return;
return title;
};
//注册全局方法
common.registerGlobalFunc(this);
// #ifdef APP-PLUS
const currentVersion = {
version: '',
platform: ''
}
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
currentVersion.version = widgetInfo.version
currentVersion.versionCode = widgetInfo.versionCode
currentVersion.platform = uni.getSystemInfoSync().platform
Vue.prototype.$current = currentVersion
this.appCheckVersion(currentVersion)
});
// #endif
// #ifdef MP-WEIXIN
this.update()
// #endif
//检查是否有openid,没有openid就调用登录接口
// if (!that.globalData.openid) {
// wx.login({
// success(res) {
// // 发起网络请求
// api.getOpenId({
// code: res.code
// }).then(result => {
// if (result.success) {
// let data = result.data;
// that.globalData.openid = data.openid;
// cache.put('openid', data.openid);
// console.log(data.openid, 'openid====')
// that.startSocket();
// }
// })
// }
// })
// } else {
// that.startSocket();
// }
},
onShow: function() {},
onHide: function() {},
methods: {
// 检测版本
appCheckVersion(currentVersion) {
uni.removeStorageSync('force')
uni.removeStorageSync('pkgurl')
// 1安卓,2苹果,3小程序
let params = {
type: currentVersion.platform == "ios" ? 2 : 1,
version: currentVersion.versionCode
}
let that = this
that.api.appCheckVersion(params).then(result => {
if (result.success) {
let data = result.data
if (data.update == 1 && data.info) {
let currentV = this.$current.versionCode
uni.setStorageSync('updateText', data.info.info)
uni.setStorageSync('versionName', data.info.versionName)
// 当前版本与需要最低版本判断
if (Number(data.info.minVersion) > Number(currentV)) {
// 整包更新
uni.setStorageSync('force', data.info.force)
uni.setStorageSync('pkgurl', data.info.pkgurl)
} else {
// 热更新优先
if (data.info.iosurl || data.info.wgturl) {
this.wgtUpdate(data.info.iosurl || data.info.wgturl)
} else if (data.info.pkgurl) {
// 安卓整包更新
uni.setStorageSync('force', data.info.force)
uni.setStorageSync('pkgurl', data.info.pkgurl)
}
}
}
}
}, err => {})
},
wgtUpdate(wgtUrl) {
uni.downloadFile({
url: wgtUrl,
success: (downloadResult) => {
if (downloadResult.statusCode === 200) {
plus.runtime.install(downloadResult.tempFilePath, {
force: false
}, function() {
// plus.runtime.restart();
}, function(e) {});
}
}
});
},
// 检测小程序是否有新版更新
update() {
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function(res) {
if (res.hasUpdate) {
updateManager.onUpdateReady(function() {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function(res) {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function() {
wx.showModal({
title: '已经有新版本了哟~',
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
})
})
}
})
} else {
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
},
startSocket() {
ws.connectSocket()
}
}
};
</script>
<style>
@import "./static/font/iconfont.css";
@import "components/uParse/u-parse.css";
@import "static/colorui/main.css";
@import "static/colorui/icon.css";
page {
background: #F8F9F9;
}
</style>
<style lang="scss">
@import "uview-ui/index.scss";
@import "style/common/style.css";
// 修改uview 按钮样式
.custom-style-btn-w200 /deep/ button {
width: 200upx !important;
}
.csports /deep/ .indicator-dots-active {
background-color: $myMainColor !important
}
.msearch /deep/ .u-swiper-item {
// width: 590upx !important;
}
.msearch /deep/ .u-swiper-image {
// width: 600upx !important;
border-radius: 20upx !important;
overflow: hidden !important;
}
.custom-style-btn-bg /deep/ button {
background: $myMainColor !important;
color: #FFFFFF !important;
}
.custom-style-btn-bg88 /deep/ button {
background: $myMainColor !important;
color: #FFFFFF !important;
}
.u-icon {
text-align: center !important;
}
::-webkit-scrollbar {
width: 0 !important
}
.line-style {
display: inline-block;
width: 8rpx;
height: 24rpx;
background: #21B4FD;
border-radius: 10rpx 10rpx 10rpx 10rpx;
}
</style>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/miao852265816/lxs.git
git@gitee.com:miao852265816/lxs.git
miao852265816
lxs
lxs
main

搜索帮助