login.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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="11"
  8. placeholder="请输入手机号" v-model="formData.username" />
  9. <view class="uni-row uni-jcsb uni-ais" style="width: 82%;">
  10. <input class="input" style="width: 48%; margin-right: 10px;" placeholder-class="input-placeholder" type="text" maxlength="6"
  11. placeholder="请输入验证码" v-model="formData.vfcode" />
  12. <button class="btnSendVfcode" style="padding: 0px;" :disabled="!sendVfCode.state"
  13. @click="sendVfcodeClick">
  14. <view v-if="sendVfCode.state">
  15. 获取验证码
  16. </view>
  17. <view v-else class="uni-row uni-jcc">
  18. <uni-countdown color="#c6c6c6" @timeup="timeup" :show-day="false" :showHour="false"
  19. :showMinute="false" :second="sendVfCode.counttime"></uni-countdown>
  20. 秒后重试
  21. </view>
  22. </button>
  23. </view>
  24. <button class="button" @click="login">登 录</button>
  25. <!-- <text class="hint">没有账号?点击 <text style="color: #FF8D1A;" @click="registerClick">注册</text></text> -->
  26. </view>
  27. <view class="bottomLogo"></view>
  28. </view>
  29. <text class="bottomText">&copy; 彩图奔跑 All Rights Reserved.</text>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. mapState,
  35. mapGetters
  36. } from 'vuex';
  37. import tools from '/utils/tools';
  38. import {
  39. apiSmsSend,
  40. apiSignIn
  41. } from '/utils/api.js';
  42. export default {
  43. data() {
  44. return {
  45. sendVfCode: {
  46. state: true,
  47. counttime: 30 // 倒计时 秒
  48. },
  49. formData: {
  50. username: "",
  51. vfcode: "",
  52. }
  53. }
  54. },
  55. computed: {
  56. /* ...mapState([
  57. 'username', // 映射 this.username 为 store.state.username
  58. 'token'
  59. ]), */
  60. ...mapGetters([
  61. 'metadata'
  62. ]),
  63. },
  64. onLoad() {
  65. },
  66. methods: {
  67. smsSend() {
  68. uni.request({
  69. url: apiSmsSend,
  70. header: this.metadata,
  71. method: "POST",
  72. data: {
  73. phone: this.formData.username,
  74. },
  75. success: (res) => {
  76. // console.log("smsSend", res);
  77. if (res.data.code == 0) {
  78. } else {
  79. uni.showToast({
  80. title: `验证码发送失败:${res.data.message}`,
  81. icon: 'none',
  82. duration: 5000
  83. });
  84. }
  85. },
  86. fail: (err) => {
  87. console.log("smsSend err", err);
  88. },
  89. });
  90. },
  91. login() {
  92. if (this.formData.username.length != 11) {
  93. uni.showToast({
  94. title: '请输入合法的手机号',
  95. icon: 'none'
  96. });
  97. return;
  98. }
  99. if (!tools.isPhone(this.formData.username)) {
  100. return;
  101. }
  102. if (!(this.formData.vfcode.length >= 4)) {
  103. uni.showToast({
  104. title: '请输入合法的验证码',
  105. icon: 'none'
  106. });
  107. return;
  108. }
  109. uni.request({
  110. url: apiSignIn,
  111. header: this.metadata,
  112. method: "POST",
  113. data: {
  114. username: this.formData.username,
  115. vfCode: this.formData.vfcode
  116. },
  117. success: (res) => {
  118. console.log("login", res);
  119. if (res.data.code == 0) {
  120. const data = res.data.data;
  121. this.$store.commit("setUsername", data.userName);
  122. this.$store.commit("setUserlevel", data.level);
  123. this.$store.commit("setToken", data.token);
  124. uni.showToast({
  125. title: `登录成功`,
  126. icon: 'none',
  127. duration: 3000
  128. });
  129. setTimeout(() => {
  130. const url = '/pages/actManage/index';
  131. tools.appAction(url, "uni.switchTab");
  132. }, 100);
  133. } else {
  134. uni.showToast({
  135. title: `登录失败: ${res.data.message}`,
  136. icon: 'none',
  137. duration: 5000
  138. });
  139. }
  140. },
  141. fail: (err) => {
  142. console.log("login err", err);
  143. },
  144. });
  145. },
  146. /* registerClick() {
  147. const url = "/pages/login/register";
  148. tools.appAction(url, "uni.navigateTo");
  149. }, */
  150. sendVfcodeClick() {
  151. if (this.formData.username.length != 11) {
  152. uni.showToast({
  153. title: '请输入合法的手机号',
  154. icon: 'none'
  155. });
  156. return;
  157. }
  158. if (!tools.isPhone(this.formData.username)) {
  159. return;
  160. }
  161. this.sendVfCode.state = false;
  162. this.smsSend();
  163. },
  164. // 倒计时结束
  165. timeup() {
  166. this.sendVfCode.state = true;
  167. }
  168. }
  169. }
  170. </script>
  171. <style scoped>
  172. .body-bg {
  173. width: 100vw;
  174. height: 100vh;
  175. background: url("/static/bg_login.png") no-repeat;
  176. background-size: 100% 100%;
  177. /* background-size: 100% auto; */
  178. justify-content: space-between;
  179. }
  180. .main {
  181. width: 90%;
  182. /* height: 590px; */
  183. margin-top: 10%;
  184. justify-content: space-evenly;
  185. }
  186. .topLogo {
  187. width: 90px;
  188. height: 110px;
  189. background: url("/static/run.png") no-repeat;
  190. background-size: contain;
  191. }
  192. .title {
  193. margin: 10px 0px;
  194. font-weight: 500;
  195. color: #ffffff;
  196. font-size: 30px;
  197. text-align: center;
  198. }
  199. .box {
  200. /* width: 317px; */
  201. width: 92%;
  202. height: 237px;
  203. padding-top: 10px;
  204. padding-bottom: 10px;
  205. justify-content: space-evenly;
  206. background-color: white;
  207. border-radius: 13px;
  208. box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.16);
  209. }
  210. .input {
  211. width: 72%;
  212. height: 46px;
  213. padding: 0 5%;
  214. border: 1px solid;
  215. border-color: #c6c6c6;
  216. border-radius: 3px;
  217. }
  218. .input-placeholder {
  219. font-weight: 300;
  220. color: #bfbfbf;
  221. font-size: 16px;
  222. }
  223. .btnSendVfcode {
  224. width: 50%;
  225. height: 47px;
  226. font-size: 16px;
  227. line-height: 47px;
  228. }
  229. .button {
  230. width: 82%;
  231. background: #ffb40b;
  232. border-radius: 6px;
  233. font-weight: 500;
  234. color: #333333;
  235. word-spacing: 15px;
  236. }
  237. .hint {
  238. font-size: 16px;
  239. font-weight: 500;
  240. color: #383838;
  241. }
  242. .bottomLogo {
  243. width: 232px;
  244. height: 36px;
  245. margin-top: 20px;
  246. background: url("/static/ctbp.png") no-repeat;
  247. background-size: contain;
  248. }
  249. .bottomText {
  250. margin-bottom: 30px;
  251. font-weight: 500;
  252. color: #000000;
  253. font-size: 12px;
  254. text-align: center;
  255. }
  256. </style>