index.vue 4.3 KB

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