index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. console.log(res)
  102. if(res.status == 200){
  103. this.$store.state.vuex_userData = this.fiterAuthCode(res.data.auth_user)
  104. this.$store.state.vuex_token = res.data.access_token
  105. this.$store.state.vuex_user = res.data.auth_user
  106. // 记住用户密码
  107. this.$store.state.vuex_userAccount = {
  108. username: this.username,
  109. password: this.password
  110. }
  111. uni.setStorageSync('account',this.$store.state.vuex_userAccount)
  112. uni.redirectTo({
  113. url: "/pages/index/index"
  114. })
  115. }
  116. uni.hideLoading()
  117. }else{
  118. uni.$u.toast("请输入用户名和密码")
  119. }
  120. }
  121. },
  122. }
  123. </script>
  124. <style lang="scss">
  125. .u-login{
  126. display: flex;
  127. flex-direction: column;
  128. justify-content: space-around;
  129. height: 100vh;
  130. .u-logo{
  131. text-align: center;
  132. padding-top: 20%;
  133. image{
  134. width: 150upx;
  135. height: 150upx;
  136. border-radius: 250upx;
  137. }
  138. > view{
  139. font-size: 50upx;
  140. padding: 10upx 0;
  141. }
  142. }
  143. .u-forms{
  144. width: 80%;
  145. margin: 0 auto 20%;
  146. .uni-form-item{
  147. display: flex;
  148. align-items: center;
  149. position: relative;
  150. margin: 30upx 0;
  151. border-bottom: 1px solid #eee;
  152. border-radius: 20upx;
  153. padding: 20upx 10upx;
  154. .uni-form-title{
  155. padding: 0 15upx;
  156. text{
  157. font-size: 50upx;
  158. color: $uni-text-color-grey;
  159. }
  160. }
  161. .uni-input{
  162. flex-grow: 1;
  163. padding: 0 15upx;
  164. &:focus{
  165. border-color: $uni-color-primary;
  166. }
  167. }
  168. .uni-icon{
  169. position: absolute;
  170. right: 20upx;
  171. color: $uni-text-color-grey;
  172. }
  173. }
  174. .uni-btn-v{
  175. padding: 30upx 20%;
  176. button{
  177. background: $uni-color-primary;
  178. font-size: 36upx;
  179. }
  180. }
  181. }
  182. .copright{
  183. text-align: center;
  184. color: $uni-text-color-grey;
  185. font-size: 20upx;
  186. }
  187. }
  188. </style>