index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view class="u-login">
  3. <view class="u-logo">
  4. <image class="logo" src="/static/logo.png"></image>
  5. <view>iSCM 检货系统</view>
  6. </view>
  7. <view class="u-forms">
  8. <form @submit="AndroidCheckUpdate">
  9. <view class="uni-form-item">
  10. <view class="uni-form-title">
  11. <text class="iconfont icon-icon-test23"></text>
  12. </view>
  13. <input class="uni-input" v-model="username" name="username" placeholder="请输入用户名" />
  14. </view>
  15. <view class="uni-form-item">
  16. <view class="uni-form-title">
  17. <text class="iconfont icon-icon-test16"></text>
  18. </view>
  19. <input class="uni-input" v-model="password" name="password" password placeholder="请输入密码" />
  20. </view>
  21. <view class="uni-btn-v">
  22. <button form-type="submit" type="primary">登录</button>
  23. </view>
  24. </form>
  25. </view>
  26. <view class="copright">
  27. <view>系统版本:{{version}}</view>
  28. <view>Copyright © 2023 陕西山海高科信息技术有限公司</view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import { login, getSysVersion } from '@/config/api.js'
  34. import { checkVersionToLoadUpdate } from '@/libs/tools.js'
  35. export default {
  36. data() {
  37. return {
  38. showPassword: false,
  39. username: '',
  40. password: '',
  41. version: ''
  42. };
  43. },
  44. onLoad() {
  45. //#ifdef APP-PLUS
  46. uni.getSystemInfo({
  47. success:(res) => {
  48. console.log(res)
  49. // 获取最新版本信息
  50. plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
  51. wgtinfo.platform = res.platform
  52. getApp().globalData.version = wgtinfo
  53. const curr_version = wgtinfo && wgtinfo.version || ''
  54. this.version = curr_version
  55. })
  56. }
  57. })
  58. //#endif
  59. const devInfo = uni.getDeviceInfo()
  60. this.$store.state.vuex_deviceId = devInfo.deviceId
  61. // 记住用户密码
  62. const account = uni.getStorageSync('account')
  63. if(account){
  64. this.username = account.username
  65. this.password = account.password
  66. }
  67. },
  68. methods: {
  69. // 版本更新
  70. AndroidCheckUpdate(){
  71. let _this = this
  72. uni.showLoading({
  73. title: '正在登录...'
  74. });
  75. getSysVersion({versionType:uni.getSystemInfoSync().platform == "ios"?'IOS':'ANDROID', applyCode: 'scsb'}).then(ret => {
  76. console.log(ret)
  77. if(ret.status == 200){
  78. if(ret.data){
  79. this.$store.state.vuex_versionInfo = ret.data || null
  80. checkVersionToLoadUpdate(ret.data,0,_this.formSubmit)
  81. }else{
  82. _this.formSubmit();
  83. }
  84. }
  85. uni.hideLoading()
  86. })
  87. },
  88. // 过滤权限code
  89. fiterAuthCode(data) {
  90. data.permCodes = data.permCodes.filter(item => item.indexOf('_mobile') > 0);
  91. return data;
  92. },
  93. // 登录
  94. async formSubmit(e) {
  95. const formdata = {
  96. username: this.username,
  97. password: this.password
  98. }
  99. if(formdata.username && formdata.password){
  100. const res = await login(formdata)
  101. if(res.status == 200){
  102. this.$store.state.vuex_userData = this.fiterAuthCode(res.data.auth_user)
  103. this.$store.state.vuex_token = res.data.access_token
  104. this.$store.state.vuex_user = res.data.auth_user
  105. // 记住用户密码
  106. this.$store.state.vuex_userAccount = {
  107. username: this.username,
  108. password: this.password
  109. }
  110. uni.setStorageSync('account',this.$store.state.vuex_userAccount)
  111. uni.redirectTo({
  112. url: "/pages/index/index"
  113. })
  114. }
  115. uni.hideLoading()
  116. }else{
  117. uni.$u.toast("请输入用户名和密码")
  118. }
  119. }
  120. },
  121. }
  122. </script>
  123. <style lang="scss">
  124. .u-login{
  125. display: flex;
  126. flex-direction: column;
  127. justify-content: space-around;
  128. height: 100vh;
  129. .u-logo{
  130. text-align: center;
  131. padding-top: 20%;
  132. image{
  133. width: 150upx;
  134. height: 150upx;
  135. border-radius: 250upx;
  136. }
  137. > view{
  138. font-size: 50upx;
  139. padding: 10upx 0;
  140. }
  141. }
  142. .u-forms{
  143. width: 80%;
  144. margin: 0 auto 20%;
  145. .uni-form-item{
  146. display: flex;
  147. align-items: center;
  148. position: relative;
  149. margin: 30upx 0;
  150. border-bottom: 1px solid #eee;
  151. border-radius: 20upx;
  152. padding: 20upx 10upx;
  153. .uni-form-title{
  154. padding: 0 15upx;
  155. text{
  156. font-size: 50upx;
  157. color: $uni-text-color-grey;
  158. }
  159. }
  160. .uni-input{
  161. flex-grow: 1;
  162. padding: 0 15upx;
  163. &:focus{
  164. border-color: $uni-color-primary;
  165. }
  166. }
  167. .uni-icon{
  168. position: absolute;
  169. right: 20upx;
  170. color: $uni-text-color-grey;
  171. }
  172. }
  173. .uni-btn-v{
  174. padding: 30upx 20%;
  175. button{
  176. background: $uni-color-primary;
  177. font-size: 36upx;
  178. }
  179. }
  180. }
  181. .copright{
  182. text-align: center;
  183. color: $uni-text-color-grey;
  184. font-size: 20upx;
  185. }
  186. }
  187. </style>