register.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. <uni-forms ref="form" class="form" :modelValue="formData" :rules="rules">
  8. <uni-forms-item label="" name="username">
  9. <input class="input" placeholder-class="input-placeholder" type="text" maxlength="15"
  10. placeholder="请输入用户名" v-model="formData.username" />
  11. </uni-forms-item>
  12. <uni-forms-item label="" name="password">
  13. <input class="input" placeholder-class="input-placeholder" password type="text" maxlength="15"
  14. placeholder="请输入密码" v-model="formData.password" />
  15. </uni-forms-item>
  16. <uni-forms-item label="" name="repassword">
  17. <input class="input" placeholder-class="input-placeholder" password type="text" maxlength="15"
  18. placeholder="请再次输入密码" v-model="formData.repassword" />
  19. </uni-forms-item>
  20. <uni-forms-item label="" name="phone">
  21. <input class="input" placeholder-class="input-placeholder" type="tel" maxlength="11"
  22. placeholder="请输入手机号" v-model="formData.phone" />
  23. </uni-forms-item>
  24. <view class="uni-row uni-jcsb uni-ais">
  25. <uni-forms-item label="" name="vfcode" style="width: 48%; margin-right: 10px;">
  26. <input class="input" placeholder-class="input-placeholder" type="text" maxlength="6"
  27. placeholder="请输入验证码" v-model="formData.vfcode" />
  28. </uni-forms-item>
  29. <button class="btnSendVfcode" style="padding: 0px;" :disabled="!sendVfCode.state"
  30. @click="sendVfcodeClick">
  31. <view v-if="sendVfCode.state">
  32. 获取验证码
  33. </view>
  34. <view v-else class="uni-row uni-jcc">
  35. <uni-countdown color="#c6c6c6" @timeup="timeup" :show-day="false" :showHour="false"
  36. :showMinute="false" :second="sendVfCode.counttime"></uni-countdown>
  37. 秒后重试
  38. </view>
  39. </button>
  40. </view>
  41. </uni-forms>
  42. <button class="button" @click="registerClick">注 册</button>
  43. <text class="hint">已有账号?点击 <text style="color: #FF8D1A;" @click="loginClick">登录</text></text>
  44. </view>
  45. <view class="bottomLogo"></view>
  46. </view>
  47. <text class="bottomText">&copy; 彩图奔跑 All Rights Reserved.</text>
  48. </view>
  49. </template>
  50. <script>
  51. import {
  52. mapState,
  53. mapGetters
  54. } from 'vuex';
  55. import tools from '/utils/tools';
  56. import {
  57. apiSmsSend,
  58. apiSignUp
  59. } from '/utils/api.js';
  60. export default {
  61. data() {
  62. return {
  63. sendVfCode: {
  64. state: true,
  65. counttime: 30 // 倒计时 秒
  66. },
  67. formData: {
  68. username: "",
  69. password: "",
  70. repassword: "",
  71. phone: "",
  72. vfcode: "",
  73. },
  74. rules: {
  75. username: {
  76. rules: [{
  77. required: true,
  78. errorMessage: '请输入用户名',
  79. },
  80. {
  81. minLength: 3,
  82. maxLength: 15,
  83. errorMessage: '用户名长度在 {minLength} 到 {maxLength} 个字符',
  84. }
  85. ]
  86. },
  87. password: {
  88. rules: [{
  89. required: true,
  90. errorMessage: '请输入密码',
  91. },
  92. {
  93. minLength: 6,
  94. maxLength: 15,
  95. errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符',
  96. }
  97. ]
  98. },
  99. repassword: {
  100. rules: [{
  101. required: true,
  102. errorMessage: '请再次输入密码',
  103. },
  104. {
  105. validateFunction: function(rule, value, data, callback) {
  106. if (value != data.password) {
  107. callback('两次输入的密码不一致');
  108. return false;
  109. } else {
  110. return true;
  111. }
  112. }
  113. }
  114. ]
  115. },
  116. phone: {
  117. rules: [{
  118. required: true,
  119. errorMessage: '请输入手机号',
  120. },
  121. {
  122. pattern: "^((1[3456789][0-9]{1})+\\d{8})$",
  123. errorMessage: '请输入合法的手机号',
  124. }
  125. ]
  126. },
  127. vfcode: {
  128. rules: [{
  129. required: true,
  130. errorMessage: '请输入验证码',
  131. },
  132. {
  133. minLength: 4,
  134. maxLength: 6,
  135. errorMessage: '请输入合法的验证码',
  136. }
  137. ]
  138. }
  139. }
  140. }
  141. },
  142. onLoad() {
  143. // console.log("metadata:", this.metadata);
  144. // console.log("token:", this.$store.state.token);
  145. // this.$store.commit('setToken', "123456");
  146. // console.log("token:", this.$store.state.token);
  147. },
  148. computed: {
  149. ...mapGetters([
  150. 'metadata'
  151. ]),
  152. },
  153. methods: {
  154. smsSend() {
  155. uni.request({
  156. url: apiSmsSend,
  157. header: this.metadata,
  158. method: "POST",
  159. data: {
  160. phone: this.formData.phone,
  161. },
  162. success: (res) => {
  163. console.log("smsSend", res);
  164. if (res.data.code == 0) {
  165. } else {
  166. uni.showToast({
  167. title: `验证码发送失败:${res.data.message}`,
  168. icon: 'none',
  169. duration: 5000
  170. });
  171. }
  172. },
  173. fail: (err) => {
  174. console.log("smsSend err", err);
  175. },
  176. });
  177. },
  178. register() {
  179. uni.request({
  180. url: apiSignUp,
  181. header: this.metadata,
  182. method: "POST",
  183. data: {
  184. phone: this.formData.phone,
  185. username: this.formData.username,
  186. password: this.formData.password,
  187. vfCode: this.formData.vfcode
  188. },
  189. success: (res) => {
  190. console.log("register", res);
  191. if (res.data.code == 0) {
  192. const data = res.data.data;
  193. this.$store.commit("setUsername", data.userName);
  194. this.$store.commit("setUserlevel", data.level);
  195. this.$store.commit("setToken", data.token);
  196. uni.showToast({
  197. title: `注册成功`,
  198. icon: 'none',
  199. duration: 3000
  200. });
  201. setTimeout(() => {
  202. const url = '/pages/actManage/index';
  203. tools.appAction(url, "uni.switchTab");
  204. }, 100);
  205. } else {
  206. uni.showToast({
  207. title: `注册失败:${res.data.message}`,
  208. icon: 'none',
  209. duration: 5000
  210. });
  211. }
  212. },
  213. fail: (err) => {
  214. console.log("register err", err);
  215. },
  216. });
  217. },
  218. registerClick() {
  219. this.$refs.form.validate().then(res => {
  220. // console.log('表单数据信息:', res);
  221. this.register();
  222. }).catch(err => {
  223. // console.log('表单错误信息:', err);
  224. });
  225. },
  226. loginClick() {
  227. const url = "/pages/login/login";
  228. tools.appAction(url, "uni.navigateTo");
  229. },
  230. sendVfcodeClick() {
  231. // 部分表单进行校验,接受一个参数,类型为 String 或 Array ,只校验传入 name 表单域的值
  232. this.$refs.form.validateField(['phone']).then((res) => {
  233. // 成功返回,res 为对应表单数据
  234. this.sendVfCode.state = false;
  235. this.smsSend();
  236. }).catch((err) => {
  237. // 表单校验验失败,err 为具体错误信息
  238. });
  239. },
  240. // 倒计时结束
  241. timeup() {
  242. this.sendVfCode.state = true;
  243. }
  244. }
  245. }
  246. </script>
  247. <style scoped>
  248. .body-bg {
  249. width: 100vw;
  250. height: 100vh;
  251. background: url("/static/bg_login.png") no-repeat;
  252. background-size: 100% 100%;
  253. /* background-size: 100% auto; */
  254. justify-content: space-between;
  255. }
  256. .main {
  257. width: 90%;
  258. /* height: 590px; */
  259. margin-top: 10%;
  260. justify-content: space-evenly;
  261. }
  262. .topLogo {
  263. width: 90px;
  264. height: 110px;
  265. background: url("/static/run.png") no-repeat;
  266. background-size: contain;
  267. }
  268. .title {
  269. margin: 10px 0px;
  270. font-weight: 500;
  271. color: #ffffff;
  272. font-size: 30px;
  273. text-align: center;
  274. }
  275. .box {
  276. width: 92%;
  277. padding-top: 25px;
  278. padding-bottom: 20px;
  279. justify-content: space-evenly;
  280. background-color: white;
  281. border-radius: 13px;
  282. box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.16);
  283. }
  284. .form {
  285. width: 80%;
  286. }
  287. .input {
  288. width: 90%;
  289. height: 36px;
  290. padding: 0 5%;
  291. border: 1px solid;
  292. border-color: #c6c6c6;
  293. border-radius: 3px;
  294. }
  295. .input-placeholder {
  296. font-weight: 300;
  297. color: #bfbfbf;
  298. font-size: 14px;
  299. }
  300. .btnSendVfcode {
  301. width: 48%;
  302. height: 38px;
  303. font-size: 13px;
  304. line-height: 38px;
  305. }
  306. .button {
  307. width: 82%;
  308. margin: 5px 0px;
  309. background: #ffb40b;
  310. border-radius: 6px;
  311. font-weight: 500;
  312. color: #333333;
  313. word-spacing: 15px;
  314. }
  315. .hint {
  316. margin-top: 10px;
  317. font-size: 16px;
  318. font-weight: 500;
  319. color: #383838;
  320. }
  321. .bottomLogo {
  322. width: 232px;
  323. height: 36px;
  324. margin-top: 20px;
  325. background: url("/static/ctbp.png") no-repeat;
  326. background-size: contain;
  327. }
  328. .bottomText {
  329. margin-bottom: 30px;
  330. font-weight: 500;
  331. color: #000000;
  332. font-size: 12px;
  333. text-align: center;
  334. }
  335. </style>