index.vue 4.9 KB

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