LoginSupplier.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="login-container">
  3. <view class="uni-padding-wrap uni-common-mt">
  4. <form @submit="formSubmit" >
  5. <view class="uni-form-item uni-column" style="background-color: #fff;">
  6. <image style="width:61px;height: 61px;margin: 5px auto;" :src="src" ></image>
  7. </view>
  8. <org-input-text left-text="账号" placeholder="请输入账号" :check-info="{msg:'账号至少2位',reg:'^.{1,}$',required:true}" v-model="username" >
  9. <!-- 使用插槽,自定义左侧文本 -->
  10. <view slot="left" >
  11. <uni-icons type="person" size="30" color="#6666" style="padding-left: 10rpx;"></uni-icons>
  12. </view>
  13. </org-input-text>
  14. <org-input-text left-text="密码" :is-password="true" placeholder="请输入密码" :check-info="{msg:'账号至少4位',reg:'^.{1,}$',required:true}" v-model="password" >
  15. <!-- 使用插槽,自定义左侧文本 -->
  16. <view slot="left" style="padding-left: 10rpx;">
  17. <uni-icons type="eye" size="30" color="#6666"></uni-icons>
  18. </view>
  19. </org-input-text>
  20. <view class="uni-btn-v uni-column">
  21. <button type="primary" form-type="submit" style="border-radius: 15px;" >登录</button>
  22. </view>
  23. </form>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. loginsupplier,
  30. getInfo,
  31. logout
  32. } from "@/common/api/loginApi.js";
  33. var graceChecker = require("../../common/graceChecker.js");
  34. import {
  35. setToken,getToken
  36. } from "@/common/auth.js"
  37. //import store from '@/store/index.js'
  38. var duration = 2000;
  39. export default {
  40. data() {
  41. return {
  42. username:'',
  43. password:'',
  44. //isSupplier:'',
  45. src: '/static/haode.png'
  46. }
  47. },
  48. created: function() {
  49. var abc=1;
  50. if(typeof abc=='string'){
  51. console.info(typeof abc);
  52. console.info(abc);
  53. }
  54. else{
  55. console.info(typeof abc,abc);
  56. }
  57. },
  58. methods: {
  59. onInput1:function(){
  60. console.info("oninput1");
  61. console.info(this.username);
  62. //console.log(this.username);
  63. },
  64. onInput2:function(){
  65. console.info("oninput2");
  66. console.info(this.password);
  67. //console.log(this.password);
  68. },
  69. formSubmit: function(e) {
  70. //console.log('form发生了submit事件,携带数据为:' + JSON.stringify(e.detail.value))
  71. //定义表单规则
  72. var rule = [{
  73. name: "username",
  74. checkType: "string",
  75. checkRule: "2,22",
  76. errorMsg: "账号应为2-22个字符"
  77. },
  78. {
  79. name: "password",
  80. checkType: "string",
  81. checkRule: "4,",
  82. errorMsg: "密码必须大于4位"
  83. }
  84. ];
  85. //console.info(this.username);
  86. //console.info(this.password);
  87. //console.info("isSupplier",this.isSupplier);
  88. //return;
  89. let formData={username:this.username,password:this.password};
  90. //进行表单检查
  91. //var formData = e.detail.value;
  92. var checkRes = graceChecker.check(formData, rule);
  93. //console.info(formData);
  94. //return;
  95. if (checkRes) {
  96. //uni.showToast({title:"验证通过!", icon:"none"});
  97. this.loading = true;
  98. //this.$store.dispatch('user/login', this.formData)
  99. loginsupplier(formData)
  100. .then((res) => {
  101. console.info(res);
  102. if (!res.isSuccess) //失败,显示错误
  103. {
  104. uni.showToast({
  105. title: res.errMsg,
  106. icon: 'none'
  107. });
  108. return;
  109. }
  110. //return;
  111. //设置状态中的各种值
  112. this.$store.commit('setIsLogin',true);
  113. this.$store.commit('setToken',res.tnToken);
  114. this.$store.commit('setAvatar','');
  115. this.$store.commit('setName',res.data.supplier.supplierName);
  116. this.$store.commit('setIntroduction','');
  117. this.$store.commit('setRoles','');
  118. this.$store.commit('setUser',res.data.supplier);
  119. this.$store.commit('setStationName','');
  120. this.$store.commit('setStationCode','');
  121. this.$store.commit('setDepartmentName','');
  122. this.$store.commit('setDepartmentCode','');
  123. console.info("登录页面state:",this.$store.state);
  124. uni.setStorage({
  125. key:'storage_state',
  126. data:this.$store.state,
  127. success:function(){
  128. console.info("setStorage状态缓存成功");
  129. console.info('storage_state',uni.getStorageSync('storage_state'));
  130. },
  131. fail: () => {
  132. console.error("setStorage状态缓存失败");
  133. }
  134. });
  135. this.loading = false;
  136. //导向到首页
  137. uni.navigateTo({
  138. url: "/pages/template/SupplierList/SupplierList"
  139. });
  140. })
  141. .catch((error) => {
  142. console.log(error);
  143. this.loading = false;
  144. })
  145. } else {
  146. uni.showToast({
  147. title: graceChecker.error,
  148. icon: "none"
  149. });
  150. }
  151. }
  152. }
  153. }
  154. </script>
  155. <style scoped>
  156. .login-container {
  157. display: flex;
  158. width: 400px;
  159. margin: 50px auto;
  160. }
  161. </style>