login - 副本.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. <text class="hint">没有账号?点击 <text style="color: #FF8D1A;" @click="registerClick">注册</text></text>
  13. </view>
  14. <view class="bottomLogo"></view>
  15. </view>
  16. <text class="bottomText">&copy; 彩图奔跑 All Rights Reserved.</text>
  17. </view>
  18. </template>
  19. <script>
  20. import {
  21. mapState,
  22. mapGetters
  23. } from 'vuex';
  24. import tools from '/utils/tools';
  25. import {
  26. apiSignIn
  27. } from '/utils/api.js';
  28. export default {
  29. data() {
  30. return {
  31. username: "",
  32. password: "",
  33. }
  34. },
  35. computed: {
  36. /* ...mapState([
  37. 'username', // 映射 this.username 为 store.state.username
  38. 'token'
  39. ]), */
  40. ...mapGetters([
  41. 'metadata'
  42. ]),
  43. },
  44. onLoad() {
  45. },
  46. methods: {
  47. login() {
  48. uni.request({
  49. url: apiSignIn,
  50. header: this.metadata,
  51. method: "POST",
  52. data: {
  53. username: this.username,
  54. password: this.password
  55. },
  56. success: (res) => {
  57. console.log("login", res);
  58. if (res.data.code == 0) {
  59. const data = res.data.data;
  60. this.$store.commit("setUsername", data.userName);
  61. this.$store.commit("setUserlevel", data.level);
  62. this.$store.commit("setToken", data.token);
  63. uni.showToast({
  64. title: `登录成功`,
  65. icon: 'none',
  66. duration: 3000
  67. });
  68. setTimeout(() => {
  69. const url = '/pages/actManage/index';
  70. tools.appAction(url, "uni.switchTab");
  71. }, 100);
  72. } else {
  73. uni.showToast({
  74. title: `登录失败: ${res.data.message}`,
  75. icon: 'none',
  76. duration: 5000
  77. });
  78. }
  79. },
  80. fail: (err) => {
  81. console.log("login err", err);
  82. },
  83. });
  84. },
  85. registerClick() {
  86. const url = "/pages/login/register";
  87. tools.appAction(url, "uni.navigateTo");
  88. }
  89. }
  90. }
  91. </script>
  92. <style scoped>
  93. .body-bg {
  94. width: 100vw;
  95. height: 100vh;
  96. background: url("/static/bg_login.png") no-repeat;
  97. background-size: 100% 100%;
  98. /* background-size: 100% auto; */
  99. justify-content: space-between;
  100. }
  101. .main {
  102. width: 90%;
  103. /* height: 590px; */
  104. margin-top: 10%;
  105. justify-content: space-evenly;
  106. }
  107. .topLogo {
  108. width: 90px;
  109. height: 110px;
  110. background: url("/static/run.png") no-repeat;
  111. background-size: contain;
  112. }
  113. .title {
  114. margin: 10px 0px;
  115. font-weight: 500;
  116. color: #ffffff;
  117. font-size: 30px;
  118. text-align: center;
  119. }
  120. .box {
  121. /* width: 317px; */
  122. width: 92%;
  123. height: 237px;
  124. padding-top: 10px;
  125. padding-bottom: 10px;
  126. justify-content: space-evenly;
  127. background-color: white;
  128. border-radius: 13px;
  129. box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.16);
  130. }
  131. .input {
  132. width: 72%;
  133. height: 46px;
  134. padding: 0 5%;
  135. border: 1px solid;
  136. border-color: #c6c6c6;
  137. border-radius: 3px;
  138. }
  139. .input-placeholder {
  140. font-weight: 300;
  141. color: #bfbfbf;
  142. font-size: 16px;
  143. }
  144. .button {
  145. width: 82%;
  146. background: #ffb40b;
  147. border-radius: 6px;
  148. font-weight: 500;
  149. color: #333333;
  150. word-spacing: 15px;
  151. }
  152. .hint {
  153. font-size: 16px;
  154. font-weight: 500;
  155. color: #383838;
  156. }
  157. .bottomLogo {
  158. width: 232px;
  159. height: 36px;
  160. margin-top: 20px;
  161. background: url("/static/ctbp.png") no-repeat;
  162. background-size: contain;
  163. }
  164. .bottomText {
  165. margin-bottom: 30px;
  166. font-weight: 500;
  167. color: #000000;
  168. font-size: 12px;
  169. text-align: center;
  170. }
  171. </style>