diff --git a/login/login.js b/login/login.js deleted file mode 100644 index 7a234e7..0000000 --- a/login/login.js +++ /dev/null @@ -1,127 +0,0 @@ -// pages/login/login.js -Page({ - data: { - ID: '', // 用户输入的 ID - password: '', // 用户输入的密码 - errorMessage: '' // 错误信息提示 - }, - - // 处理 ID 输入 - onIDInput(e) { - this.setData({ - ID: e.detail.value // 将输入的ID存储到 data 中 - }); - this.clearErrorMessage(); // 清除错误提示 - }, - - // 处理密码输入 - onPasswordInput(e) { - this.setData({ - password: e.detail.value // 将输入的密码存储到 data 中 - }); - this.clearErrorMessage(); // 清除错误提示 - }, - - // 清除错误信息 - clearErrorMessage() { - if (this.data.errorMessage) { - this.setData({ errorMessage: '' }); - } - }, - - // 检查管理员状态 - checkAdminStatus() { - const token = getApp().globalData.token || wx.getStorageSync('token'); - if (!token) { - this.setData({ errorMessage: 'Token 丢失,请重新登录' }); - return; - } - console.log("Checking admin status with token:", token); // 输出 token 确认 - - wx.request({ - header: { - 'Authorization': `${token}`, // 使用存储的 token - 'content-type': 'application/x-www-form-urlencoded' - }, - url: 'http://192.168.144.1:8080/user/is_admin', // 管理员状态查询接口 - method: 'GET', - success: (res) => { - console.log("Admin status response:", res); // 输出请求返回数据 - if (res.data.data) { - wx.navigateTo({ - url: '/pages/admin/admin' // 管理员页面 - }); - } else { - wx.switchTab({ - url: '/pages/home/home' // 普通用户主页 - }); - } - }, - fail: (error) => { - console.log("Admin status check failed", error); - this.setData({ - errorMessage: '无法验证管理员状态,请稍后再试' - }); - } - }); - }, - - submitUserInfo() { - const { ID, password } = this.data; - - if (!ID || !password) { - this.setData({ - errorMessage: 'ID和密码不能为空' - }); - return; - } - - wx.request({ - header: { - 'content-type': 'application/x-www-form-urlencoded' - }, - url: 'http://192.168.144.1:8080/user/login', - method: 'POST', - data: { - 'username': ID, - 'password': password - }, - success: (res) => { - if (res.data.code == 0) { - wx.showToast({ - title: '登录成功', - icon: 'success' - }); - - // 检查 getApp() 和 globalData 是否定义 - const appInstance = getApp(); - if (appInstance && appInstance.globalData) { - appInstance.globalData.token = res.data.data; - wx.setStorageSync('token', res.data.data); - } else { - console.error("App instance or globalData is not initialized"); - } - - this.checkAdminStatus(); - } else { - this.setData({ - errorMessage: res.data.message || '登录失败,请检查ID和密码' - }); - } - }, - fail: (error) => { - console.log('登录失败', error); - this.setData({ - errorMessage: '网络请求失败,请稍后再试' - }); - } - }); - }, - - // 跳转到注册页面 - goToRegister() { - wx.redirectTo({ - url: '/pages/register/register' // 跳转到注册页面 - }); - } -}); diff --git a/login/login.json b/login/login.json deleted file mode 100644 index 8835af0..0000000 --- a/login/login.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "usingComponents": {} -} \ No newline at end of file diff --git a/login/login.wxml b/login/login.wxml deleted file mode 100644 index ad5f9dc..0000000 --- a/login/login.wxml +++ /dev/null @@ -1,31 +0,0 @@ - - - 登录 - - - - - - - - - {{errorMessage}} - - - - - - - 还没有账号?点击注册 - - diff --git a/login/login.wxss b/login/login.wxss deleted file mode 100644 index 919e6f3..0000000 --- a/login/login.wxss +++ /dev/null @@ -1,80 +0,0 @@ -/* pages/login/login.wxss */ -page { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - height: 100vh; - background-color: #f8f8f8; -} - -.container { - width: 90%; - max-width: 400px; - background-color: #fff; - border-radius: 10px; - padding: 20px; - box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); -} - -.title { - text-align: center; - font-size: 24px; - font-weight: bold; - color: #333; - margin-bottom: 20px; -} - -input { - width: 100%; - height: 40px; - padding: 0 10px; - margin-bottom: 15px; - border: 1px solid #ddd; - border-radius: 5px; - background-color: #fafafa; -} - -input:focus { - border-color: #007aff; - background-color: #fff; -} - -button { - width: 100%; - height: 45px; - background-color: #007aff; - color: #fff; - border: none; - border-radius: 5px; - font-size: 16px; - text-align: center; - line-height: 45px; - margin-top: 10px; -} - -button:active { - background-color: #005bb5; -} - -.admin-section { - margin-bottom: 15px; -} - -.error { - color: red; - font-size: 14px; - margin-top: 5px; -} - -.message { - margin-top: 10px; - text-align: center; - color: #666; -} - -.link { - color: #007aff; - text-decoration: underline; - cursor: pointer; -} diff --git a/register/register.js b/register/register.js deleted file mode 100644 index 32bf028..0000000 --- a/register/register.js +++ /dev/null @@ -1,66 +0,0 @@ -// pages/register/register.js -Page({ - data: { - ID: '', - password: '', - errorMessage: '' - }, - - // 处理ID输入 - onIDInput(e) { - this.setData({ - ID: e.detail.value - }); - }, - - // 处理密码输入 - onPasswordInput(e) { - this.setData({ - password: e.detail.value - }); - }, - - // 处理注册逻辑 - submitUserInfo() { - const { ID, password } = this.data; - - // 验证 ID 和密码是否为空 - if (!ID || !password) { - this.setData({ - errorMessage: '账号ID和密码不能为空' - }); - return; - } - - // 发起注册请求,使用 x-www-form-urlencoded - wx.request({ - header: { - 'content-type': 'application/x-www-form-urlencoded' // 设置请求头 - }, - url: 'http://192.168.144.1:8080/user/register', // 替换为你的后端API地址 - method: 'POST', - data: { - 'username': ID, - 'password': password - }, - success(res) { - console.log('注册成功', res); - wx.showToast({ - title: '注册成功', - icon: 'success' - }); - // 注册成功后跳转到登录页面 - wx.redirectTo({ - url: '/pages/login/login' - }); - }, - }); - }, - - // 跳转到登录页面 - goToLogin() { - wx.redirectTo({ - url: '/pages/login/login' // 登录页面的路径 - }); - } -}); diff --git a/register/register.json b/register/register.json deleted file mode 100644 index 8835af0..0000000 --- a/register/register.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "usingComponents": {} -} \ No newline at end of file diff --git a/register/register.wxml b/register/register.wxml deleted file mode 100644 index de3e8c4..0000000 --- a/register/register.wxml +++ /dev/null @@ -1,32 +0,0 @@ - - - - 注册 - - - - - - - - - {{errorMessage}} - - - - - - - 已有账号?点击登录 - - diff --git a/register/register.wxss b/register/register.wxss deleted file mode 100644 index bfe364c..0000000 --- a/register/register.wxss +++ /dev/null @@ -1,76 +0,0 @@ -/* pages/register/register.wxss */ -page { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - height: 100vh; - background-color: #f8f8f8; -} - -.container { - width: 90%; - max-width: 400px; - background-color: #fff; - border-radius: 10px; - padding: 20px; - box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); -} - -.title { - text-align: center; - font-size: 24px; - font-weight: bold; - color: #333; - margin-bottom: 20px; -} - -input { - width: 100%; - height: 40px; - padding: 0 10px; - margin-bottom: 15px; - border: 1px solid #ddd; - border-radius: 5px; - background-color: #fafafa; -} - -input:focus { - border-color: #007aff; - background-color: #fff; -} - -button { - width: 100%; - height: 45px; - background-color: #007aff; - color: #fff; - border: none; - border-radius: 5px; - font-size: 16px; - text-align: center; - line-height: 45px; - margin-top: 10px; -} - -button:active { - background-color: #005bb5; -} - -.error { - color: red; - font-size: 14px; - margin-top: 5px; -} - -.message { - margin-top: 10px; - text-align: center; - color: #666; -} - -.link { - color: #007aff; - text-decoration: underline; - cursor: pointer; -}