| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const utils_api = require("../../utils/api.js");
- const _sfc_main = {
- data() {
- return {
- formData: {
- username: "",
- nickname: "",
- password: "",
- confirmPassword: "",
- phone: "",
- email: ""
- },
- showPassword: false,
- showConfirmPassword: false,
- isLoading: false
- };
- },
- computed: {
- canRegister() {
- return this.formData.username.trim().length > 0 && this.formData.password.length >= 6 && this.formData.password === this.formData.confirmPassword && !this.isLoading;
- }
- },
- methods: {
- togglePassword() {
- this.showPassword = !this.showPassword;
- },
- toggleConfirmPassword() {
- this.showConfirmPassword = !this.showConfirmPassword;
- },
- validateForm() {
- if (!this.formData.username || this.formData.username.trim().length === 0) {
- common_vendor.index.showToast({
- title: "请输入用户名",
- icon: "none"
- });
- return false;
- }
- if (!this.formData.password || this.formData.password.length < 6) {
- common_vendor.index.showToast({
- title: "密码长度不能少于6位",
- icon: "none"
- });
- return false;
- }
- if (this.formData.password.length > 20) {
- common_vendor.index.showToast({
- title: "密码长度不能超过20位",
- icon: "none"
- });
- return false;
- }
- if (this.formData.password !== this.formData.confirmPassword) {
- common_vendor.index.showToast({
- title: "两次输入的密码不一致",
- icon: "none"
- });
- return false;
- }
- if (this.formData.phone && this.formData.phone.trim().length > 0) {
- const phoneReg = /^1[3-9]\d{9}$/;
- if (!phoneReg.test(this.formData.phone.trim())) {
- common_vendor.index.showToast({
- title: "请输入正确的手机号",
- icon: "none"
- });
- return false;
- }
- }
- if (this.formData.email && this.formData.email.trim().length > 0) {
- const emailReg = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
- if (!emailReg.test(this.formData.email.trim())) {
- common_vendor.index.showToast({
- title: "请输入正确的邮箱地址",
- icon: "none"
- });
- return false;
- }
- }
- return true;
- },
- handleRegister() {
- if (!this.validateForm()) {
- return;
- }
- this.isLoading = true;
- common_vendor.index.showLoading({
- title: "注册中...",
- mask: true
- });
- const registerData = {
- username: this.formData.username.trim(),
- password: this.formData.password,
- nickname: this.formData.nickname.trim() || this.formData.username.trim(),
- phone: this.formData.phone.trim() || null,
- email: this.formData.email.trim() || null
- };
- utils_api.register(registerData).then((res) => {
- common_vendor.index.hideLoading();
- this.isLoading = false;
- if (res.code === 200 && res.data) {
- common_vendor.index.showToast({
- title: "注册成功",
- icon: "success"
- });
- setTimeout(() => {
- common_vendor.index.redirectTo({
- url: `/pages/login/login?username=${encodeURIComponent(registerData.username)}`
- });
- }, 1500);
- } else {
- common_vendor.index.showToast({
- title: res.message || "注册失败",
- icon: "none",
- duration: 2e3
- });
- }
- }).catch((err) => {
- common_vendor.index.hideLoading();
- this.isLoading = false;
- common_vendor.index.__f__("error", "at pages/register/register.vue:261", "注册失败:", err);
- common_vendor.index.showToast({
- title: err.message || "注册失败,请检查网络连接",
- icon: "none",
- duration: 2e3
- });
- });
- },
- goToLogin() {
- common_vendor.index.navigateBack();
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return {
- a: $data.formData.username,
- b: common_vendor.o(($event) => $data.formData.username = $event.detail.value),
- c: $data.formData.nickname,
- d: common_vendor.o(($event) => $data.formData.nickname = $event.detail.value),
- e: $data.showPassword ? "text" : "password",
- f: $data.formData.password,
- g: common_vendor.o(($event) => $data.formData.password = $event.detail.value),
- h: common_vendor.t($data.showPassword ? "隐藏" : "显示"),
- i: common_vendor.o((...args) => $options.togglePassword && $options.togglePassword(...args)),
- j: $data.showConfirmPassword ? "text" : "password",
- k: $data.formData.confirmPassword,
- l: common_vendor.o(($event) => $data.formData.confirmPassword = $event.detail.value),
- m: common_vendor.t($data.showConfirmPassword ? "隐藏" : "显示"),
- n: common_vendor.o((...args) => $options.toggleConfirmPassword && $options.toggleConfirmPassword(...args)),
- o: $data.formData.phone,
- p: common_vendor.o(($event) => $data.formData.phone = $event.detail.value),
- q: $data.formData.email,
- r: common_vendor.o(($event) => $data.formData.email = $event.detail.value),
- s: common_vendor.t($data.isLoading ? "注册中..." : "注册"),
- t: common_vendor.o((...args) => $options.handleRegister && $options.handleRegister(...args)),
- v: !$options.canRegister,
- w: common_vendor.o((...args) => $options.goToLogin && $options.goToLogin(...args))
- };
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-bac4a35d"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/register/register.js.map
|