Files
c/miniprogram/pages/register/index.js
刘正航 b5237f9038 1
2026-04-21 22:45:19 +08:00

39 lines
903 B
JavaScript

const { request } = require('../../utils/request')
Page({
data: {
form: {
username: '',
password: '',
nickname: '',
company: '',
title: '',
phone: ''
},
loading: false
},
onInput(e) {
const field = e.currentTarget.dataset.field
this.setData({ [`form.${field}`]: (e.detail.value || '').trim() })
},
async submit() {
if (this.data.loading) return
const { username, password } = this.data.form
if (!username || !password) {
wx.showToast({ title: '用户名和密码必填', icon: 'none' })
return
}
this.setData({ loading: true })
try {
await request({ url: '/auth/register', method: 'POST', data: this.data.form })
wx.showToast({ title: '注册成功', icon: 'success' })
setTimeout(() => wx.navigateBack(), 350)
} finally {
this.setData({ loading: false })
}
}
})