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