Parcourir la source

app热更新,自动登录,loading,tab栏

zouling il y a 2 semaines
Parent
commit
e0b88a3dde

+ 85 - 1
App.vue

@@ -1,12 +1,96 @@
 <script>
   import config from './config'
   import { getToken } from '@/utils/auth'
-
+  import {updateUserProfile,findVersion} from "@/api/system/user.js"
+const baseUrl = config.baseUrl
   export default {
+	data(){
+		return{
+			platform:'Android',
+		}
+	},
     onLaunch: function() {
+		// #ifdef APP
+		this.onlineWgt(); //版本更新
+		// #endif
       this.initApp()
     },
     methods: {
+		// 在线跟新
+		onlineWgt() {
+			let that = this;
+			plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
+				that.comparisonVersionNo(widgetInfo.versionCode);
+			});
+			// that.comparisonVersionNo()
+		},
+		comparisonVersionNo(versionCode) {
+			let that = this;
+			// console.log("aaaaaaa===versionCode", versionCode);
+			const parmas = {
+				model: that.platform,
+				appPort:that.appPort
+			}   
+			findVersion(parmas).then(res => {
+				console.log(res)  
+				if (res.code == "200") {
+					let versionNos = res.data.code;
+					// console.log(versionNos,'versionNos')
+					let filePath = res.data.path;
+					if (Number(versionNos) > Number(versionCode)) { //服务器返回1更新,0则不更新
+						uni.showModal({
+							title: '提示',
+							content: '发现新版本,是否升级',
+							success: function(res) {
+								// console.log(widgetInfo.version);
+								if (res.confirm) {
+									console.log('用户点击确定');
+									that.getProperty(filePath);
+								} else if (res.cancel) {
+									console.log('用户点击取消');
+								}
+							}
+						});
+					}
+				}
+			}).catch(error=>{
+				uni.hideLoading()
+				console.log(error)
+			})
+		},
+		getProperty(getProperty) {
+			// console.log("bbbbbbbbb----------->", getProperty)
+			let that = this;
+			// console.log(baseUrl + getProperty)
+			// 在线升级app/热更新
+			that.showwri = true;
+			const downloadTask = uni.downloadFile({ //下载文件
+				url: baseUrl + getProperty,
+				success: (downloadResult) => {
+					// console.log(downloadResult);
+					if (downloadResult.statusCode == 200) {
+						// 更新升级
+						plus.runtime.install(downloadResult.tempFilePath, {
+							force: true
+						}, function() {
+							// console.log('install success...');
+							that.showwri = false;
+							plus.nativeUI.alert("应用资源更新完成!", function() {
+								plus.runtime.restart();
+							});
+						}, function(e) {
+							that.showwri = false;
+							plus.nativeUI.alert("更新失败,请稍后再试");
+						});
+					}
+				}
+			});
+			downloadTask.onProgressUpdate((res) => { //下载文件的进度
+				that.totalBytesWritten = res.totalBytesWritten; //当前下载大小
+				that.progress = res.progress; //当前下载比例
+				that.totalBytesExpectedToWrite = res.totalBytesExpectedToWrite; //
+			});
+		},
       // 初始化应用
       initApp() {
         // 初始化应用配置

+ 9 - 1
api/system/user.js

@@ -21,7 +21,15 @@ export function getUserProfile() {
     method: 'get'
   })
 }
-
+// 下载版本更新
+export function findVersion(data) {
+  return request({
+    url: '/system/app/new',
+    method: 'get',
+    data: data,
+	lhide:true,
+  })
+}
 // 修改用户个人信息
 export function updateUserProfile(data) {
   return request({

+ 82 - 0
components/footer/footer.vue

@@ -0,0 +1,82 @@
+<template>
+	<view>
+		
+	
+	<view style="height: 100rpx;"></view>
+    <view class="com_footer">
+		<block v-for="(item,k) in footlist" :key="k">
+			<!-- v-if="!item.limit||item.limit&&checkPermi([item.limit])" -->
+			<view class="in_item"   @click="gotopage(item)">
+				<view class="im_imgs">
+					<image class="in_img" :class="item.img" v-if="active == item.module" :src="item.icon_checked" mode="scaleToFill"></image>
+					<image class="in_img" :class="item.img" v-else :src="item.icon_nochecked" mode="scaleToFill"></image>
+				</view>
+				<view class="in_txt" v-if="active == item.module" :style="'color: #'+color_checked">{{item.title}}</view>
+				<view class="in_txt" v-else :style="'color: #'+color_nochecked">{{item.title}}</view>
+			</view>
+		</block>
+    </view>
+	</view>
+</template>
+
+<script>
+	import { checkPermi, checkRole } from "@/utils/permission";
+    export default {
+		props:[
+			'footerindex'
+		],
+        data () {
+            return{
+				active :'',
+				footlist:[
+					// limit:'system:camera:video',
+					// {module:'home',title:'首页',img:"imga",icon_checked:require('@/static/images/tabbar/home_.png'),icon_nochecked:require('@/static/images/tabbar/home.png')},
+					// {module:'health',title:'康养',img:"imgb",icon_checked:require('@/static/images/tabbar/health_.png'),icon_nochecked:require('@/static/images/tabbar/health.png')},
+					// {module:'goods',title:'商圈',img:"imgc",icon_checked:require('@/static/images/tabbar/store_.png'),icon_nochecked:require('@/static/images/tabbar/store.png')},
+					// {module:'mine',title:'我的',img:"imgd",icon_checked:require('@/static/images/tabbar/mine_.png'),icon_nochecked:require('@/static/images/tabbar/mine.png')},
+					],
+				color_checked :'272727',
+				color_nochecked :'666666',
+            }
+        },
+		mounted() {
+			var that = this;
+			this.active = this.footerindex;
+		},
+        methods:{
+			checkPermi, checkRole,
+            // 跳转底部导航页面
+			gotopage(e){
+				var that = this;
+				let link = e.link, module = e.module, def = e.default, title = e.title;
+				if(module == 'home'){
+					this.$tab.reLaunch('/pages/index/index')
+				}else if(module == 'health'){
+					this.$tab.reLaunch('/pages/health/index')
+				}else if(module == 'goods'){
+					this.$tab.reLaunch('/pages/goods/index')
+				}else if(module == 'mine'){
+					this.$tab.reLaunch('/pages/mine/index')
+				}
+			},
+			
+        }
+    }
+</script>
+
+
+
+<style type="text/css" lang="scss" scoped>
+    .com_footer{ display: flex;position: fixed;box-sizing: border-box;z-index: 4;width: 100%;height: 100rpx;bottom: 0;left: 0;background-color: #fff;overflow: hidden;box-shadow: 0px 0px 16rpx 0px rgba(87,87,87,0.41);}
+	.com_footer .in_item{ display: block;flex: 1;padding: 12rpx 0 0 0;overflow: hidden; }
+	.com_footer .in_img{ display: block;width: 44rpx;height: 44rpx;margin: 0 auto; }
+	.com_footer .in_txt{ font-size: 24rpx;color: #999;text-align: center; font-weight: bold;}
+	.com_footer .in_txt_on{ color: #20AD20; }
+	.im_imgs{width: 48rpx;height: 48rpx;display: flex;align-items: center;justify-content: center;margin: 0 auto;}
+	.in_img{
+		&.imga{width: 44rpx;height: 42rpx;}
+		&.imgb{width: 44rpx;height: 40rpx;}
+		&.imgc{width: 44rpx;height: 44rpx;}
+		&.imgd{width: 42rpx;height: 44rpx;}
+	}
+</style>

+ 235 - 0
components/loading/loading - 副本.vue

@@ -0,0 +1,235 @@
+<!-- <template>
+	<view>
+		
+		<view class="loading" v-if="is_loading">
+			
+			<image class="load_img" :src="waimai ? '../../../static/loading/loading2.gif' : '../../static/loading/loading2.gif'" mode=""></image>
+			
+		</view>
+		
+	</view>
+</template> -->
+
+<template>
+	<view class="" v-if="is_loading">
+		<view class="loader">
+				
+		</view>
+	</view>
+</template>
+
+<script>
+	export default {
+		props: ["waimai"],
+		data() {
+			return {
+				
+			}
+		},
+		methods:{
+			switch_loading(){
+				this.$store.commit("switch_loading")
+			}
+		},
+		//实测直接在标签属性里写  $store.state.XX  拿不到数据  所以这里通过 计算属性去监听一下
+		computed:{
+			is_loading(){
+				return this.$store.state.user.loading
+			}
+		}
+	}
+</script>
+
+<style scoped>
+	.loading{position: fixed;top: 0;left: 0;bottom: 0;right: 0;display: flex;align-items: center;justify-content: space-around;z-index: 1001;background: transparent;}
+	.load_img{width: 640rpx;height: 490rpx;}
+	
+	.loader,
+	.loader:before,
+	.loader:after {
+	  -webkit-animation: load1 1s infinite ease-in-out;
+	  animation: load1 1s infinite ease-in-out;
+	  width: 1em;
+	  height: 3em;
+	}
+	.loader {
+	  color: #FF8080;
+	  background: #FF8080;
+	  text-indent: -9999em;
+	  margin: 88px auto;
+	  position: fixed;
+	  font-size: 16upx;
+	  -webkit-transform: translateZ(0);
+	  -ms-transform: translateZ(0);
+	  transform: translateZ(0);
+	  -webkit-animation-delay: -0.16s;
+	  animation-delay: -0.16s;
+	  top: 30%;left: 0;bottom: 0;right: 0;
+	}
+	.loader:before,
+	.loader:after {
+	  position: absolute;
+	  top: 0;
+	  content: '';
+	}
+	.loader:before {
+	  left: -1.5em;
+	  -webkit-animation-delay: -0.32s;
+	  animation-delay: -0.32s;
+	  background: #FF9999;
+	  color: #FF9999;
+	}
+	.loader:after {
+	  left: 1.5em;
+	  background: #FE6666;
+	  color: #FE6666;
+	}
+	@-webkit-keyframes load1 {
+	  0%,
+	  80%,
+	  100% {
+		box-shadow: 0 0;
+		height: 2em;
+	  }
+	  40% {
+		box-shadow: 0 -2em;
+		height: 3em;
+	  }
+	}
+	@keyframes load1 {
+	  0%,
+	  80%,
+	  100% {
+		box-shadow: 0 0;
+		height: 2em;
+	  }
+	  40% {
+		box-shadow: 0 -2em;
+		height: 3em;
+	  }
+	}
+	
+	/* .loader,
+	.loader:before,
+	.loader:after {
+	  border-radius: 50%;
+	  width: 2.5em;
+	  height: 2.5em;
+	  -webkit-animation-fill-mode: both;
+	  animation-fill-mode: both;
+	  -webkit-animation: load7 1.8s infinite ease-in-out;
+	  animation: load7 1.8s infinite ease-in-out;
+	}
+	.loader {
+	  color: #000;
+	  font-size: 10px;
+	  margin: 80px auto;
+	  position: fixed;
+	  text-indent: -9999em;
+	  -webkit-transform: translateZ(0);
+	  -ms-transform: translateZ(0);
+	  transform: translateZ(0);
+	  -webkit-animation-delay: -0.16s;
+	  animation-delay: -0.16s;
+	  top: 30%;left: 0;bottom: 0;right: 0;
+	}
+	.loader:before,
+	.loader:after {
+	  content: '';
+	  position: absolute;
+	  top: 0;
+	}
+	.loader:before {
+	  left: -3.5em;
+	  -webkit-animation-delay: -0.32s;
+	  animation-delay: -0.32s;
+	}
+	.loader:after {
+	  left: 3.5em;
+	}
+	@-webkit-keyframes load7 {
+	  0%,
+	  80%,
+	  100% {
+		box-shadow: 0 2.5em 0 -1.3em;
+	  }
+	  40% {
+		box-shadow: 0 2.5em 0 0;
+	  }
+	}
+	@keyframes load7 {
+	  0%,
+	  80%,
+	  100% {
+		box-shadow: 0 2.5em 0 -1.3em;
+	  }
+	  40% {
+		box-shadow: 0 2.5em 0 0;
+	  }
+	} */
+	
+	/* .loader {
+	  font-size: 10px;
+	  margin: 50px auto;
+	  text-indent: -9999em;
+	  width: 8em;
+	  height: 8em;
+	  border-radius: 50%;
+	  background: transparent ;
+	  background: -moz-linear-gradient(left, #CCCCCC 10%, rgba(255, 255, 255, 0) 42%);
+	  background: -webkit-linear-gradient(left, #CCCCCC 10%, rgba(255, 255, 255, 0) 42%);
+	  background: -o-linear-gradient(left, #CCCCCC 10%, rgba(255, 255, 255, 0) 42%);
+	  background: -ms-linear-gradient(left, #CCCCCC 10%, rgba(255, 255, 255, 0) 42%);
+	  background: linear-gradient(to right, #CCCCCC 10%, rgba(255, 255, 255, 0) 42%);
+	  position: fixed;
+	  top: 30%;left: 0;bottom: 0;right: 0;
+	  -webkit-animation: load3 1.4s infinite linear;
+	  animation: load3 1.4s infinite linear;
+	  -webkit-transform: translateZ(0);
+	  -ms-transform: translateZ(0);
+	  transform: translateZ(0);
+	}
+	.loader:before {
+	  width: 50%;
+	  height: 50%;
+	  background: transparent ;
+	  border-radius: 100% 0 0 0;
+	  position: absolute;
+	  top: 0;
+	  left: 0;
+	  content: '';
+	}
+	.loader:after {
+	  background: #FFFFFF ;
+	  width: 75%;
+	  height: 75%;
+	  border-radius: 50%;
+	  content: '';
+	  margin: auto;
+	  position: absolute;
+	  top: 0;
+	  left: 0;
+	  bottom: 0;
+	  right: 0;
+	}
+	@-webkit-keyframes load3 {
+	  0% {
+		-webkit-transform: rotate(0deg);
+		transform: rotate(0deg);
+	  }
+	  100% {
+		-webkit-transform: rotate(360deg);
+		transform: rotate(360deg);
+	  }
+	}
+	@keyframes load3 {
+	  0% {
+		-webkit-transform: rotate(0deg);
+		transform: rotate(0deg);
+	  }
+	  100% {
+		-webkit-transform: rotate(360deg);
+		transform: rotate(360deg);
+	  }
+	} */
+</style>

+ 96 - 0
components/loading/loading.vue

@@ -0,0 +1,96 @@
+<template>
+  <view class="animations" v-if="is_loading">
+    <view class="box">
+      <view class="dot dot1"></view>
+      <view class="dot dot2"></view>
+      <view class="dot dot3"></view>
+    </view>
+  </view>
+</template>
+
+<script>
+export default {
+  name: "loading-bounce",
+  data() {
+    return {};
+  },
+  methods:{
+  	switch_loading(){
+  		this.$store.commit("switch_loading")
+  	}
+  },
+  //实测直接在标签属性里写  $store.state.XX  拿不到数据  所以这里通过 计算属性去监听一下
+  computed:{
+  	is_loading(){
+  		return this.$store.state.user.loading
+  	}
+  }
+};
+</script>
+
+<style lang="scss" scoped>
+	.animations{display: flex;align-items: center;justify-content: center;position: fixed;top: 40%;left: 0;right: 0;z-index: 3;}
+.box {
+  width: 100rpx;
+  height: 50rpx;
+  position: relative;
+}
+.dot {
+  width: 18rpx;
+  height: 18rpx;
+  background: #007aff;
+  border-radius: 50%;
+  position: absolute;
+  top: calc(50% - 5rpx);
+}
+
+.dot1 {
+  background: #1fa2ff;
+  left: 0rpx;
+  -webkit-animation: bounce 0.5s cubic-bezier(0.77, 0.47, 0.64, 0.28) alternate
+    infinite;
+  animation: bounce 0.5s cubic-bezier(0.77, 0.47, 0.64, 0.28) alternate infinite;
+}
+
+.dot2 {
+  background: #12d8fa;
+  left: 40rpx;
+  -webkit-animation: bounce 0.5s 0.2s cubic-bezier(0.77, 0.47, 0.64, 0.28)
+    alternate infinite;
+  animation: bounce 0.5s 0.2s cubic-bezier(0.77, 0.47, 0.64, 0.28) alternate
+    infinite;
+}
+
+.dot3 {
+  background: #29ffc6;
+  left: 80rpx;
+  -webkit-animation: bounce 0.5s 0.4s cubic-bezier(0.77, 0.47, 0.64, 0.28)
+    alternate infinite;
+  animation: bounce 0.5s 0.4s cubic-bezier(0.77, 0.47, 0.64, 0.28) alternate
+    infinite;
+}
+
+@-webkit-keyframes bounce {
+  0% {
+    -webkit-transform: translateY(0);
+    transform: translateY(0);
+  }
+
+  100% {
+    -webkit-transform: translateY(-20rpx);
+    transform: translateY(-20rpx);
+  }
+}
+
+@keyframes bounce {
+  0% {
+    -webkit-transform: translateY(0);
+    transform: translateY(0);
+  }
+
+  100% {
+    -webkit-transform: translateY(-20rpx);
+    transform: translateY(-20rpx);
+  }
+}
+</style>

+ 12 - 0
main.js

@@ -7,6 +7,18 @@ import { getDicts } from "@/api/system/dict/data"
 
 Vue.use(plugins)
 
+/** 
+ * 引用全局加载 loading
+ * */
+import loading from "./components/loading/loading.vue"
+Vue.component('loading',loading);
+//是否显示加载中 的方法 调用store中的mutations方法
+function loadings(tf){
+	store.commit("switch_loading",tf);
+}
+//也挂在到原型链上 方便在每个页面中  使用 this.$loading()  去显示加载中
+Vue.prototype.$loading = loadings;
+
 Vue.config.productionTip = false
 Vue.prototype.$store = store
 Vue.prototype.getDicts = getDicts

+ 2 - 2
manifest.json

@@ -62,8 +62,8 @@
         },
         "title" : "RuoYi-App",
         "router" : {
-            "mode" : "hash",
-            "base" : "./"
+            "mode" : "history",
+            "base" : ""
         }
     }
 }

+ 18 - 0
package-lock.json

@@ -0,0 +1,18 @@
+{
+  "name": "prevent_drowning_app",
+  "lockfileVersion": 3,
+  "requires": true,
+  "packages": {
+    "": {
+      "dependencies": {
+        "jsencrypt": "^3.3.2"
+      }
+    },
+    "node_modules/jsencrypt": {
+      "version": "3.3.2",
+      "resolved": "https://registry.npmjs.org/jsencrypt/-/jsencrypt-3.3.2.tgz",
+      "integrity": "sha512-arQR1R1ESGdAxY7ZheWr12wCaF2yF47v5qpB76TtV64H1pyGudk9Hvw8Y9tb/FiTIaaTRUyaSnm5T/Y53Ghm/A==",
+      "license": "MIT"
+    }
+  }
+}

+ 5 - 0
package.json

@@ -0,0 +1,5 @@
+{
+  "dependencies": {
+    "jsencrypt": "^3.3.2"
+  }
+}

+ 20 - 2
pages/login.vue

@@ -41,7 +41,8 @@
 <script>
   import { getCodeImg } from '@/api/login'
   import { getToken } from '@/utils/auth'
-
+  import { encrypt, decrypt } from '@/utils/jsencrypt'
+  import config from '@/config'
   export default {
     data() {
       return {
@@ -55,7 +56,8 @@
           password: "admin123",
           code: "",
           uuid: ""
-        }
+        },
+		jzflag:true
       }
     },
     created() {
@@ -108,9 +110,25 @@
       },
       // 密码登录
       async pwdLogin() {
+		  var that=this;
         this.$store.dispatch('Login', this.loginForm).then(() => {
+			// 判断是否记住密码
+			if(that.jzflag){
+				var newObj={
+					username:that.loginForm.username,
+					password:encrypt(that.loginForm.password),
+					captchaEnabled:that.captchaEnabled,
+				}					  
+				uni.setStorageSync('account', JSON.parse(JSON.stringify(newObj)))
+			}else{
+				uni.removeStorageSync('account')
+			} 
           this.$modal.closeLoading()
           this.loginSuccess()
+		  this.$modal.msg('登录成功')
+		  setTimeout(function(){
+		  	that.loginSuccess()
+		  },1500)
         }).catch(() => {
           if (this.captchaEnabled) {
             this.getCode()

+ 103 - 2
pages/mine/index.vue

@@ -77,12 +77,23 @@
 </template>
 
 <script>
+	import footers from '@/components/footer/footer.vue'
+	import {findVersion} from "@/api/system/user.js"
+	import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
+	import config from '@/config'
+	const baseUrl = config.baseUrl
   export default {
     data() {
       return {
-        name: this.$store.state.user.name
+		footerindex: 'mine',
+		isfootflag: true,
+		wgtcode: this.$store.state.user.wgtcode,
+		platform: 'Android',
+        name: this.$store.state.user.name,
+		nvaHeight:44,
       }
     },
+	components: {footers},
     computed: {
       avatar() {
         return this.$store.state.user.avatar
@@ -91,7 +102,19 @@
         return uni.getSystemInfoSync().windowHeight - 50
       }
     },
+	onLoad() {
+		var that=this;
+		this.nvaHeight=uni.getSystemInfoSync().statusBarHeight+44;
+		// #ifdef APP-PLUS
+		plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
+			that.$store.dispatch('SetwgtFn', widgetInfo.version).then(() => {
+				that.wgtcode=widgetInfo.version
+			})
+		});
+		// #endif
+	},
     methods: {
+		checkPermi,checkRole,
       handleToInfo() {
         this.$tab.navigateTo('/pages/mine/info/index')
       },
@@ -118,7 +141,85 @@
       },
       handleBuilding() {
         this.$modal.showToast('模块建设中~')
-      }
+      },
+	  onlineWgt() {
+	  	let that = this;
+	  	plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
+	  		that.$store.dispatch('SetwgtFn', widgetInfo.version).then(() => {
+	  			that.wgtcode=widgetInfo.version
+	  		})
+	  		that.comparisonVersionNo(widgetInfo.versionCode);
+	  	});
+	  	// that.comparisonVersionNo()
+	  },
+	  comparisonVersionNo(versionCode) {
+	  	let that = this;
+	  	// console.log("aaaaaaa===versionCode", versionCode);
+	  	const parmas = {
+	  		model: that.platform,
+	  		appPort:that.appPort
+	  	}
+	  	findVersion(parmas).then(res => {
+	  		if (res.code == "200") {
+	  			let versionNos = res.data.code;
+	  			console.log(versionNos, 'versionNos')
+	  			// console.log(res.data.path);
+	  			let filePath = res.data.path;
+	  			if (Number(versionNos) > Number(versionCode)) { //服务器返回1更新,0则不更新
+	  				uni.showModal({
+	  					title: '提示',
+	  					content: '发现新版本,是否升级',
+	  					success: function(res) {
+	  						// console.log(widgetInfo.version);
+	  						if (res.confirm) {
+	  							console.log('用户点击确定');
+	  							that.getProperty(filePath);
+	  						} else if (res.cancel) {
+	  							console.log('用户点击取消');
+	  						}
+	  					}
+	  				});
+	  			} else {
+	  				this.$toast('该版本已是最新版')
+	  			}
+	  		}
+	  	}).catch(error => {
+	  		uni.hideLoading()
+	  		console.log(error)
+	  	})
+	  },
+	  getProperty(getProperty) {
+	  	// console.log("bbbbbbbbb----------->", getProperty)
+	  	let that = this;
+	  	// 在线升级app/热更新
+	  	that.showwri = true;
+	  	const downloadTask = uni.downloadFile({ //下载文件
+	  		url: baseUrl + getProperty,
+	  		success: (downloadResult) => {
+	  			// console.log(downloadResult);
+	  			if (downloadResult.statusCode == 200) {
+	  				// 更新升级
+	  				plus.runtime.install(downloadResult.tempFilePath, {
+	  					force: true
+	  				}, function() {
+	  					// console.log('install success...');
+	  					that.showwri = false;
+	  					plus.nativeUI.alert("应用资源更新完成!", function() {
+	  						plus.runtime.restart();
+	  					});
+	  				}, function(e) {
+	  					that.showwri = false;
+	  					plus.nativeUI.alert("更新失败,请稍后再试");
+	  				});
+	  			}
+	  		}
+	  	});
+	  	downloadTask.onProgressUpdate((res) => { //下载文件的进度
+	  		that.totalBytesWritten = res.totalBytesWritten; //当前下载大小
+	  		that.progress = res.progress; //当前下载比例
+	  		that.totalBytesExpectedToWrite = res.totalBytesExpectedToWrite; //
+	  	});
+	  },
     }
   }
 </script>

+ 10 - 1
store/getters.js

@@ -4,6 +4,15 @@ const getters = {
   id: state => state.user.id,
   name: state => state.user.name,
   roles: state => state.user.roles,
-  permissions: state => state.user.permissions
+  permissions: state => state.user.permissions,
+  
+  nickName: state => state.user.nickName,
+  wgtcode:state => state.user.wgtcode,
+  autologin:state => state.user.autologin,
+  userId:state=>state.user.userId,
+  phonenumber: state => state.user.phonenumber,
+  deptName: state => state.user.deptName,
+  deptId: state => state.user.deptId,
+  loading: state => state.user.loading,
 }
 export default getters

+ 62 - 7
store/modules/user.js

@@ -15,17 +15,22 @@ const user = {
     name: storage.get(constant.name),
     avatar: storage.get(constant.avatar),
     roles: storage.get(constant.roles),
-    permissions: storage.get(constant.permissions)
+    permissions: storage.get(constant.permissions),
+	
+	userId: storage.get(constant.userId),
+	nickName: storage.get(constant.nickName),
+	wgtcode:storage.get(constant.wgtcode),
+	autologin:storage.get(constant.autologin),
+	phonenumber: storage.get(constant.phonenumber),
+	deptId: storage.get(constant.deptId),
+	deptName: storage.get(constant.deptName),
+	loading: false,
   },
 
   mutations: {
     SET_TOKEN: (state, token) => {
       state.token = token
     },
-    SET_ID: (state, id) => {
-      state.id = id
-      storage.set(constant.id, id)
-    },
     SET_NAME: (state, name) => {
       state.name = name
       storage.set(constant.name, name)
@@ -41,10 +46,51 @@ const user = {
     SET_PERMISSIONS: (state, permissions) => {
       state.permissions = permissions
       storage.set(constant.permissions, permissions)
-    }
+    },
+	
+	SET_USERID: (state, userId) => {
+	  state.userId = userId
+	  storage.set(constant.userId, userId)
+	},
+	SET_NICKNAME: (state, nickName) => {
+	  state.nickName = nickName
+	  storage.set(constant.nickName, nickName)
+	},
+	SET_DEPTID: (state, deptId) => {
+	  state.deptId = deptId
+	  storage.set(constant.deptId, deptId)
+	},
+	SET_DEPNAME: (state, deptName) => {
+	  state.deptName = deptName
+	  storage.set(constant.deptName, deptName)
+	},
+	SET_WGTCODE: (state, wgtcode) => {
+	  state.wgtcode = wgtcode
+	  storage.set(constant.wgtcode, wgtcode)
+	},
+	SET_AUTOLOGIN: (state, autologin) => {
+	  state.autologin = autologin
+	  storage.set(constant.autologin, autologin)
+	},
+	SET_PHONENUMBER: (state, phonenumber) => {
+	  state.phonenumber = phonenumber
+	  storage.set(constant.phonenumber, phonenumber)
+	},
+	switch_loading(state,tf){
+		/* if(tf){
+			state.loading = tf;
+		}else{
+			state.loading = !state.loading
+		} */
+		state.loading = tf;
+	},
   },
 
   actions: {
+	// 版本号
+	SetwgtFn({ commit}, code ){
+	  	commit('SET_WGTCODE',code)
+	},
     // 登录
     Login({ commit }, userInfo) {
       const username = userInfo.username.trim()
@@ -73,15 +119,24 @@ const user = {
           }
           const userid = (isEmpty(user) || isEmpty(user.userId)) ? "" : user.userId
 		  const username = (isEmpty(user) || isEmpty(user.userName)) ? "" : user.userName
+		  const nickName = (user == null || user.nickName == "" || user.nickName == null) ? "" : user.nickName
+		   const phonenumber = (user == null || user.phonenumber == "" || user.phonenumber == null) ? "" : user.phonenumber
+		   const deptId = (user == null || user.deptId == "" || user.deptId == null) ? "" : user.deptId
+		   const deptName = (user == null || user.dept == "" || user.dept == null||user.dept.deptName==''||user.dept.deptName==null) ? "" : user.dept.deptName
 		  if (res.roles && res.roles.length > 0) {
             commit('SET_ROLES', res.roles)
             commit('SET_PERMISSIONS', res.permissions)
           } else {
             commit('SET_ROLES', ['ROLE_DEFAULT'])
           }
-          commit('SET_ID', userid)
+          commit('SET_USERID', userid)
           commit('SET_NAME', username)
           commit('SET_AVATAR', avatar)
+		  commit('SET_NICKNAME', nickName)
+		  commit('SET_PHONENUMBER', phonenumber)
+		  commit('SET_DEPTID', deptId)
+		  commit('SET_DEPNAME', deptName)
+		  commit('SET_AUTOLOGIN',true)
           resolve(res)
         }).catch(error => {
           reject(error)

+ 9 - 1
utils/constant.js

@@ -3,7 +3,15 @@ const constant = {
   id: 'user_id',
   name: 'user_name',
   roles: 'user_roles',
-  permissions: 'user_permissions'
+  permissions: 'user_permissions',
+  
+  userId: 'user_userId',
+  nickName: 'user_nickName',
+  autologin:'user_autologin',
+  wgtcode:'user_wgtcode',
+  phonenumber:'user_phonenumber',
+  deptId: 'user_deptId',
+  deptName: 'user_deptName',
  }
 
  export default constant

+ 30 - 0
utils/jsencrypt.js

@@ -0,0 +1,30 @@
+import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'
+
+// 密钥对生成 http://web.chacuo.net/netrsakeypair
+
+const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
+  'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
+
+const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' +
+  '7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' +
+  'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' +
+  'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' +
+  'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' +
+  'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' +
+  'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' +
+  'UP8iWi1Qw0Y='
+
+// 加密
+export function encrypt(txt) {
+  const encryptor = new JSEncrypt()
+  encryptor.setPublicKey(publicKey) // 设置公钥
+  return encryptor.encrypt(txt) // 对数据进行加密
+}
+
+// 解密
+export function decrypt(txt) {
+  const encryptor = new JSEncrypt()
+  encryptor.setPrivateKey(privateKey) // 设置私钥
+  return encryptor.decrypt(txt) // 对数据进行解密
+}
+

+ 91 - 9
utils/request.js

@@ -1,12 +1,21 @@
+import { encrypt, decrypt } from '@/utils/jsencrypt'
 import store from '@/store'
 import config from '@/config'
 import { getToken } from '@/utils/auth'
 import errorCode from '@/utils/errorCode'
 import { toast, showConfirm, tansParams } from '@/utils/common'
 
-let timeout = 10000
+let timeout = 60000
 const baseUrl = config.baseUrl
-
+var confirmflag = config.confirmflag
+// 获取账号密码
+var newObj=JSON.parse(JSON.stringify(uni.getStorageSync('account')))
+var username=newObj.username;
+var password=newObj.password;
+if(newObj){
+	password=decrypt(newObj.password);		
+}
+var captchaEnabled=newObj.captchaEnabled;
 const request = config => {
   // 是否需要设置 token
   const isToken = (config.headers || {}).isToken === false
@@ -20,6 +29,13 @@ const request = config => {
     url = url.slice(0, -1)
     config.url = url
   }
+  if(config.lhide){
+  	  uni.showLoading({
+  	  	title:"加载中"
+  	  })
+  }else{
+  	store.commit("switch_loading",true);
+  }
   return new Promise((resolve, reject) => {
     uni.request({
         method: config.method || 'get',
@@ -29,6 +45,8 @@ const request = config => {
         header: config.header,
         dataType: 'json'
       }).then(response => {
+		  uni.hideLoading()
+		  store.commit("switch_loading",false);
         let [error, res] = response
         if (error) {
           toast('后端接口连接异常')
@@ -38,13 +56,72 @@ const request = config => {
         const code = res.data.code || 200
         const msg = errorCode[code] || res.data.msg || errorCode['default']
         if (code === 401) {
-          showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
-            if (res.confirm) {
-              store.dispatch('LogOut').then(res => {
-                uni.reLaunch({ url: '/pages/login' })
-              })
-            }
-          })
+			if(confirmflag){
+				// 利用 return 终止函数继续运行
+				return false;
+			}
+			confirmflag = true;
+			setTimeout(function(){
+				var autologin=store.state.user.autologin;
+				if(username&&password&&!captchaEnabled&&autologin){
+					// 自动登录
+					var loginForm={
+						username:username,
+						password:password,
+						strfrom:'request'
+					}
+					store.dispatch('Login', loginForm).then((res) => {
+					  setTimeout(function(){
+						  store.dispatch('GetInfo').then(res => {
+							uni.hideLoading()
+						    // 刷新当前页
+							var routes = getCurrentPages()
+							// console.log(routes,1)
+							if(routes.length){
+								var route ='/'+routes[routes.length - 1].route;
+								
+								var fullPath =routes[routes.length - 1].options;
+								// console.log(fullPath,23)
+								var options={}
+								if(JSON.stringify(fullPath)!='{}'){
+									if(fullPath.data){
+										options=JSON.parse(decodeURIComponent(fullPath.data))
+										route=route+'?data='+encodeURIComponent(JSON.stringify(options))
+									}else{
+										//正常循环
+										var keystr='?'
+										Object.keys(fullPath).some((key,idx) => {
+											if(idx==0){
+												keystr+=key+'='+fullPath[key]
+											}else{
+												keystr+='&'+key+'='+fullPath[key]
+											}
+										})
+										route=route+keystr
+									}
+								}
+								uni.redirectTo({
+									url:route
+								})
+							}else{
+								// var roles=this.$store.state.user.roles;
+								// if(roles.indexOf('user')!=-1){
+								// 	this.$tab.reLaunch('/pages/index/home')
+								// }else{
+								// 	this.$tab.reLaunch('/pages/index/index')
+								// }
+							}
+						  })
+					  },500) 
+					})
+				}else{
+					uni.hideLoading()
+					store.dispatch('LogOut').then(res => {
+						uni.reLaunch({ url: '/pages/login' })
+					})
+				}
+			confirmflag = false;
+			},2000)
           reject('无效的会话,或者会话已过期,请重新登录。')
         } else if (code === 500) {
           toast(msg)
@@ -56,6 +133,11 @@ const request = config => {
         resolve(res.data)
       })
       .catch(error => {
+		if(config.lhide){
+		  }else{
+			store.commit("switch_loading",false);
+		  }
+		uni.hideLoading()
         let { message } = error
         if (message === 'Network Error') {
           message = '后端接口连接异常'

+ 1 - 1
utils/storage.js

@@ -4,7 +4,7 @@ import constant from './constant'
 let storageKey = 'storage_data'
 
 // 存储节点变量名
-let storageNodeKeys = [constant.avatar, constant.id, constant.name, constant.roles, constant.permissions]
+let storageNodeKeys = [constant.avatar, constant.id, constant.name, constant.roles, constant.permissions,constant.userId,constant.nickName,constant.autologin,constant.wgtcode,constant.phonenumber,constant.deptId,constant.deptName,]
 
 const storage = {
   set: function(key, value) {