123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <script>
- export default {
- onLaunch: function() {
- console.log('App Launch')
- // #ifdef APP-PLUS
- // token标志来判断
- let token= uni.getStorageSync('userInfo');
- if (token) {
- //存在则关闭启动页进入首页
- plus.navigator.closeSplashscreen();
-
- } else {
- //不存在则跳转至登录页
- // uni.reLaunch({
- // url: "/pages/login/login",
- // success: () => {
- // plus.navigator.closeSplashscreen();
- // }
- // })
- }
- // #endif
- },
- onShow: function() {
- console.log('App Show')
- },
- onHide: function() {
- console.log('App Hide')
- },
- globalData: {
- baseUrl: 'http://192.168.137.1:8888',
- userName: 'admin',
- password: '123456'
- },
- methods: {
- AppExit() {
- uni.showModal({
- //计算删除的数量
- title: '提示',
- content: '是否要退出应用?', //文章内容
- cancelText: '取消', //取消按钮的文字
- confirmText: '确定', //确定文本的文字
- cancelColor: '#007aff', //取消按钮文本颜色
- confirmColor: '#007aff', //确定按钮文本颜色
- success: function(res) {
- if (res.confirm) {
- //console.log('用户点击了确定')
- let userMsg = uni.getStorageSync('userInfo')
- if(userMsg) {
- uni.request({
- url: 'http://192.168.137.1:8888/logout',
- //自定义请求头信息
- header: {
- Authorization: 'Bearer ' + userMsg.tokenStr + '',
- 'content-type': 'application/json'
- },
- method: 'POST',
- })
- //指定移除登录后缓存的user用户信息
- uni.removeStorage({
- key: 'userInfo',
- success: function(res) {
- //console.log('清空了用户缓存信息', );
- uni.showToast({
- title: '退出应用成功',
- icon: 'success',
- duration: 500
- })
- }
- })
- }
- setTimeout(() => {
- // main.finish();
- plus.runtime.quit();
- }, 600)
- } else if (res.cancel) {
- //console.log('用户点击了取消')
- }
- }
- })
- },
- RequestData(parm) {
- return new Promise((resolve,reject) => {
- let userMsg = uni.getStorageSync('userInfo')
- // console.log(parm.data)
- uni.request({
- url: getApp().globalData.baseUrl + parm.url,
- data: parm.data,
- header: { //自定义请求头信息
- Authorization: parm.isHaveToken? 'Bearer ' + userMsg.tokenStr + '' : '',
- 'content-type': 'application/json'
- },
- timeout: 10000,
- method: parm.method,
- success: (res) => {
- resolve({
- isSuccess : true,
- data : res.data,
- retMsg : '请求成功!'
- })
- },
- fail: (res) => {
- reject({
- isSuccess : false,
- data : {},
- retMsg : '请求失败!' + res.errMsg
- })
- }
- });
- })
- }
- }
- }
- </script>
- <style>
- /* #ifndef APP-PLUS-NVUE */
- /* uni.css - 通用组件、模板样式库,可以当作一套ui库应用 */
- @import './common/uni.css';
- @import '@/static/customicons.css';
- /* H5 兼容 pc 所需 */
- /* #ifdef H5 */
- @media screen and (min-width: 768px) {
- body {
- overflow-y: scroll;
- }
- }
- /* 顶栏通栏样式 */
- /* .uni-top-window {
- left: 0;
- right: 0;
- } */
- uni-page-body {
- background-color: #F5F5F5 !important;
- min-height: 100% !important;
- height: auto !important;
- }
- .uni-top-window uni-tabbar .uni-tabbar {
- background-color: #fff !important;
- }
- .uni-app--showleftwindow .hideOnPc {
- display: none !important;
- }
- /* #endif */
- /* 以下样式用于 hello uni-app 演示所需 */
- page {
- background-color: #efeff4;
- height: 100%;
- font-size: 28rpx;
- /* line-height: 1.8; */
- }
- .fix-pc-padding {
- padding: 0 50px;
- }
- .uni-header-logo {
- padding: 30rpx;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- margin-top: 10rpx;
- }
- .uni-header-image {
- width: 100px;
- height: 100px;
- }
- .uni-hello-text {
- color: #7A7E83;
- }
- .uni-hello-addfile {
- text-align: center;
- line-height: 300rpx;
- background: #FFF;
- padding: 50rpx;
- margin-top: 10px;
- font-size: 38rpx;
- color: #808080;
- }
- /* #endif*/
- </style>
|