login.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="body body-bg">
  3. <view class="main uni-column">
  4. <view class="topLogo"></view>
  5. <text class="title">商家小程序</text>
  6. <view class="box uni-column">
  7. <input class="input" placeholder-class="input-placeholder" type="text" maxlength="20"
  8. placeholder="请输入用户名" v-model="username" />
  9. <input class="input" placeholder-class="input-placeholder" password type="text" maxlength="20"
  10. placeholder="请输入密码" v-model="password" />
  11. <button class="button" @click="login">登 录</button>
  12. </view>
  13. <view class="bottomLogo"></view>
  14. </view>
  15. <text class="bottomText">&copy; 彩图奔跑 All Rights Reserved.</text>
  16. </view>
  17. </template>
  18. <script>
  19. import tools from '/common/tools';
  20. import { apiVerfSignIn } from '../../common/api.js';
  21. export default {
  22. data() {
  23. return {
  24. username: "",
  25. password: "",
  26. }
  27. },
  28. onLoad() {
  29. },
  30. methods: {
  31. // 商家系统登录
  32. login() {
  33. uni.request({
  34. url: apiVerfSignIn,
  35. header: {
  36. "Content-Type": "application/x-www-form-urlencoded",
  37. },
  38. method: "POST",
  39. data: {
  40. username: this.username,
  41. password: this.password
  42. },
  43. success: (res) => {
  44. console.log("login", res)
  45. if (res.data.code == 0) {
  46. const data = res.data.data;
  47. const token = data.token;
  48. const shopinfo = {
  49. shopName: data.shopName
  50. }
  51. tools.setToken(token);
  52. tools.setShopInfo(shopinfo);
  53. uni.showToast({
  54. title: `登录成功`,
  55. icon: 'none',
  56. duration: 3000
  57. });
  58. uni.navigateTo({
  59. url: "/pages/index/index"
  60. });
  61. }
  62. else {
  63. uni.showToast({
  64. title: `登录失败,请重新登录`,
  65. icon: 'none',
  66. duration: 3000
  67. });
  68. }
  69. },
  70. fail: (err) => {
  71. console.log("login err", err)
  72. },
  73. });
  74. },
  75. }
  76. }
  77. </script>
  78. <style scoped>
  79. .body-bg {
  80. width: 100vw;
  81. height: 100vh;
  82. background: url("/static/bg_login.png") no-repeat;
  83. /* background-size: contain; */
  84. background-size: 100% auto;
  85. justify-content: space-between;
  86. }
  87. .main {
  88. width: 90%;
  89. height: 570px;
  90. margin-top: 15%;
  91. justify-content: space-evenly;
  92. }
  93. .topLogo {
  94. width: 90px;
  95. height: 110px;
  96. background: url("/static/run.png") no-repeat;
  97. background-size: contain;
  98. }
  99. .title {
  100. margin: 10px 0px;
  101. font-weight: 500;
  102. color: #ffffff;
  103. font-size: 30px;
  104. text-align: center;
  105. }
  106. .box {
  107. /* width: 317px; */
  108. width: 92%;
  109. height: 237px;
  110. padding-top: 10px;
  111. padding-bottom: 10px;
  112. justify-content: space-evenly;
  113. background-color: white;
  114. border-radius: 13px;
  115. box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.16);
  116. }
  117. .input {
  118. width: 72%;
  119. height: 46px;
  120. padding: 0 5%;
  121. border: 1px solid;
  122. border-color: #c6c6c6;
  123. border-radius: 3px;
  124. }
  125. .input-placeholder {
  126. font-weight: 300;
  127. color: #bfbfbf;
  128. font-size: 16px;
  129. }
  130. .button {
  131. width: 82%;
  132. background: #ffb40b;
  133. border-radius: 6px;
  134. font-weight: 500;
  135. color: #333333;
  136. word-spacing: 15px;
  137. }
  138. .bottomLogo {
  139. margin-top: 20px;
  140. width: 232px;
  141. height: 36px;
  142. background: url("/static/ctbp.png") no-repeat;
  143. background-size: contain;
  144. }
  145. .bottomText {
  146. margin-bottom: 30px;
  147. font-weight: 500;
  148. color: #000000;
  149. font-size: 12px;
  150. text-align: center;
  151. }
  152. </style>