index.vue 4.6 KB

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