357 lines
8.2 KiB
Vue
357 lines
8.2 KiB
Vue
<script>
|
||
/**
|
||
* vuex管理登录状态,具体可以参考官方登录模板示例
|
||
*/
|
||
import { mapMutations } from 'vuex';
|
||
import APPUpdate from '@/plugins/APPUpdate';
|
||
import { getClipboardData } from '@/js_sdk/h5-copy/h5-copy.js';
|
||
import config from '@/config/config';
|
||
// 区域code
|
||
import provinceList from './json/area_province.js';
|
||
import cityList from './json/area_city.js';
|
||
import districtList from './json/area_district.js';
|
||
import storage from '@/utils/storage.js'; //缓存
|
||
//初始化im
|
||
import { TUIChatKit } from '@/TUIKit';
|
||
import { loginIm } from '@/utils/handleim.js';
|
||
//解决华为上架权限描述
|
||
import { PermissionTips } from '@/utils/huawei_describe.js';
|
||
import { requestPermissions, closeModal, showModal } from '@/js_sdk/yu-app-permission/yu-app-permission.js';
|
||
|
||
export default {
|
||
// 全局属性
|
||
globalData: {
|
||
chat: null
|
||
},
|
||
data() {
|
||
return {
|
||
config,
|
||
popupView: null,
|
||
flag: false
|
||
};
|
||
},
|
||
|
||
/**
|
||
* 监听返回
|
||
*/
|
||
onBackPress(e) {
|
||
if (e.from == 'backbutton') {
|
||
let routes = getCurrentPages();
|
||
let curRoute = routes[routes.length - 1].options;
|
||
routes.forEach((item) => {
|
||
if (item.route == 'pages/tabbar/cart/cartList' || item.route.indexOf('pages/product/goods') != -1) {
|
||
uni.redirectTo({
|
||
url: item.route
|
||
});
|
||
}
|
||
});
|
||
|
||
if (curRoute.addId) {
|
||
uni.reLaunch({
|
||
url: '/pages/tabbar/cart/cartList'
|
||
});
|
||
} else {
|
||
uni.navigateBack();
|
||
}
|
||
return true; //阻止默认返回行为
|
||
}
|
||
},
|
||
methods: {
|
||
...mapMutations(['login'])
|
||
},
|
||
onLaunch: function () {
|
||
// #ifdef APP-PLUS
|
||
this.checkArguments(); // 检测启动参数
|
||
// 权限监听申请
|
||
this.onRequestPermissionListener();
|
||
APPUpdate();
|
||
this.hanleTabCenter();
|
||
// 重点是以下: 一定要监听后台恢复 !一定要
|
||
plus.globalEvent.addEventListener('newintent', (e) => {
|
||
this.checkArguments(); // 检测启动参数
|
||
});
|
||
|
||
if (storage.getHasLogin()) {
|
||
// init im
|
||
TUIChatKit.init();
|
||
console.log('IM初始化完成');
|
||
}
|
||
// 如果有缓存登录信息
|
||
console.log('是否登录', storage.getHasLogin());
|
||
if (storage.getHasLogin()) {
|
||
loginIm();
|
||
}
|
||
// #endif
|
||
|
||
// #ifdef MP-WEIXIN
|
||
this.applyUpdateWeChat();
|
||
// #endif
|
||
},
|
||
|
||
onShow() {
|
||
// #ifndef H5
|
||
this.getClipboard();
|
||
// #endif
|
||
},
|
||
methods: {
|
||
onRequestPermissionListener() {
|
||
// #ifdef APP
|
||
// 权限监听申请
|
||
// 为应用市场审核时要求:APP在调用终端权限时,应同步告知用户申请该权限的目的。此时即可使用本API,在app.vue里全局监听。
|
||
var brand = uni.getSystemInfoSync().deviceBrand;
|
||
if (brand.toLowerCase() != 'huawei' && brand.toLowerCase() != 'xiaomi') return;
|
||
this.permissionListener = uni.createRequestPermissionListener();
|
||
this.permissionListener.onRequest(async (e) => {
|
||
if (this.flag) {
|
||
return;
|
||
}
|
||
this.flag = true;
|
||
console.log('权限-1', e);
|
||
var item = e[0];
|
||
const { isSuc, msg } = await requestPermissions({
|
||
title: PermissionTips[item].title, // 申请权限时弹出框标题
|
||
content: PermissionTips[item].content, // 申请权限时弹出框内容
|
||
permissionID: item // 权限ID
|
||
});
|
||
console.log(msg);
|
||
if (!isSuc) {
|
||
if (msg != 'close') {
|
||
this.popupView = showModal({
|
||
title: PermissionTips[item].title, // 申请权限时弹出框标题
|
||
content: PermissionTips[item].content, // 申请权限时弹出框内容
|
||
permissionID: item // 权限ID
|
||
});
|
||
} else {
|
||
console.log('用户永久拒绝');
|
||
}
|
||
}
|
||
});
|
||
this.permissionListener.onComplete((e) => {
|
||
console.log('权限-2', e);
|
||
if (this.popupView) {
|
||
this.popupView.close();
|
||
}
|
||
setTimeout(() => {
|
||
this.flag = false;
|
||
}, 5000);
|
||
});
|
||
// 权限检测成功则返回 { isSuc : true} ,未授权则弹出权限询问弹窗以及权限说明窗口
|
||
|
||
// if (!isSuc) {
|
||
// return false
|
||
// }
|
||
// #endif
|
||
},
|
||
hanleTabCenter() {
|
||
// 点击中间的➕
|
||
uni.onTabBarMidButtonTap(() => {
|
||
console.log('center');
|
||
// 未登录不能发布视频
|
||
let myUserInfo = storage.getVlogUserInfo();
|
||
if (myUserInfo == null) {
|
||
uni.navigateTo({
|
||
// url: "../loginRegist/loginRegist",
|
||
url: '/pages/passport/login',
|
||
animationType: 'slide-in-bottom',
|
||
success() {
|
||
this.loginWords = '请登录';
|
||
}
|
||
});
|
||
return;
|
||
}
|
||
|
||
uni.chooseVideo({
|
||
sourceType: ['album'],
|
||
compressed: false,
|
||
success(e) {
|
||
console.log(e);
|
||
if (e.duration <= 30) {
|
||
uni.navigateTo({
|
||
url: '/pages/publish/publish?fileObjectEvent=' + JSON.stringify(e)
|
||
});
|
||
} else {
|
||
uni.showToast({
|
||
title: '时长不能超过30秒',
|
||
icon: 'none',
|
||
duration: 3000
|
||
});
|
||
}
|
||
}
|
||
});
|
||
});
|
||
},
|
||
/**
|
||
* 微信小程序版本提交更新版本 解决缓存问题
|
||
*/
|
||
applyUpdateWeChat() {
|
||
const updateManager = uni.getUpdateManager();
|
||
|
||
updateManager.onCheckForUpdate(function (res) {
|
||
// 请求完新版本信息的回调
|
||
});
|
||
|
||
updateManager.onUpdateReady(function (res) {
|
||
uni.showModal({
|
||
title: '更新提示',
|
||
content: '发现新版本,是否重启应用?',
|
||
success(res) {
|
||
if (res.confirm) {
|
||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||
updateManager.applyUpdate();
|
||
}
|
||
}
|
||
});
|
||
});
|
||
updateManager.onUpdateFailed(function (res) {
|
||
// 新的版本下载失败
|
||
});
|
||
},
|
||
|
||
// TODO 开屏广告 后续优化添加
|
||
launch() {
|
||
try {
|
||
// 获取本地存储中launchFlag标识 开屏广告
|
||
const value = uni.getStorageSync('launchFlag');
|
||
if (!value) {
|
||
// this.$u.route("/pages/index/agreement");
|
||
} else {
|
||
//app启动时打开启动广告页
|
||
var w = plus.webview.open(
|
||
'/hybrid/html/advertise/advertise.html',
|
||
'本地地址',
|
||
{
|
||
top: 0,
|
||
bottom: 0,
|
||
zindex: 999
|
||
},
|
||
'fade-in',
|
||
500
|
||
);
|
||
//设置定时器,4s后关闭启动广告页
|
||
setTimeout(function () {
|
||
plus.webview.close(w);
|
||
APPUpdate();
|
||
}, 3000);
|
||
}
|
||
} catch (e) {
|
||
// error
|
||
uni.setStorage({
|
||
key: 'launchFlag',
|
||
data: true,
|
||
success: function () {
|
||
console.log('error时存储launchFlag');
|
||
}
|
||
});
|
||
}
|
||
},
|
||
|
||
/**
|
||
* 获取粘贴板数据
|
||
*/
|
||
async getClipboard() {
|
||
let res = await getClipboardData();
|
||
/**
|
||
* 解析粘贴板数据
|
||
*/
|
||
if (res.indexOf(config.shareLink) != -1) {
|
||
uni.showModal({
|
||
title: '提示',
|
||
content: '检测到一个分享链接是否跳转?',
|
||
confirmText: '跳转',
|
||
success: function (callback) {
|
||
if (callback.confirm) {
|
||
console.log(res.split(config.shareLink));
|
||
uni.setClipboardData({
|
||
data: '',
|
||
success: () => {
|
||
const path = res.split(config.shareLink)[1];
|
||
if (path.indexOf('tabbar') != -1) {
|
||
uni.switchTab({
|
||
url: path
|
||
});
|
||
} else {
|
||
uni.navigateTo({
|
||
url: path
|
||
});
|
||
}
|
||
}
|
||
});
|
||
}
|
||
}
|
||
});
|
||
}
|
||
},
|
||
|
||
/**
|
||
* h5中打开app获取跳转app的链接并跳转
|
||
*/
|
||
checkArguments() {
|
||
// #ifdef APP-PLUS
|
||
setTimeout(() => {
|
||
const args = plus.runtime.arguments;
|
||
if (args) {
|
||
const argsStr = decodeURIComponent(args);
|
||
const path = argsStr.split('//')[1];
|
||
if (path.indexOf('tabbar') != -1) {
|
||
uni.switchTab({
|
||
url: `/${path}`
|
||
});
|
||
} else {
|
||
uni.navigateTo({
|
||
url: `/${path}`
|
||
});
|
||
}
|
||
}
|
||
});
|
||
// #endif
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
/* #ifndef APP-NVUE */
|
||
@import 'uview-ui/index.scss';
|
||
/* #endif */
|
||
|
||
// -------适配底部安全区 苹果x系列刘海屏
|
||
|
||
// #ifdef MP-WEIXIN
|
||
.mp-iphonex-bottom {
|
||
padding-bottom: constant(safe-area-inset-bottom);
|
||
padding-bottom: env(safe-area-inset-bottom);
|
||
box-sizing: content-box;
|
||
height: auto !important;
|
||
padding-top: 10rpx;
|
||
}
|
||
// #endif
|
||
|
||
/* #ifndef APP-NVUE */
|
||
body {
|
||
background-color: $bg-color;
|
||
}
|
||
/* #endif */
|
||
|
||
/************************ */
|
||
.w200 {
|
||
width: 200rpx !important;
|
||
}
|
||
|
||
.flex1 {
|
||
flex: 1; //必须父级设置flex
|
||
}
|
||
.activate-line {
|
||
background-color: #ffffff;
|
||
|
||
transition-duration: 300ms;
|
||
}
|
||
// uni-page-body,
|
||
// html,
|
||
// body,
|
||
// page {
|
||
// width: 100% ;
|
||
// height: 100% ;
|
||
// overflow: hidden;
|
||
// }
|
||
</style>
|