From da8bcb04c946a9e59188b7b4572c6796011e43be Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Wed, 29 Oct 2025 11:48:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=8D=E5=AF=86=E7=99=BB=E5=BD=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/application/store/config/route.php | 4 +- .../store/controller/LoginController.php | 27 ++++-- Store_vue/api/config/index.js | 4 +- Store_vue/api/modules/auth.js | 12 +++ Store_vue/pages/login/index.vue | 85 +++++++++++++++++++ 5 files changed, 123 insertions(+), 9 deletions(-) diff --git a/Server/application/store/config/route.php b/Server/application/store/config/route.php index dbae6f08..c5fcfe0f 100644 --- a/Server/application/store/config/route.php +++ b/Server/application/store/config/route.php @@ -45,4 +45,6 @@ Route::group('v1/store', function () { Route::get('detail', 'app\store\controller\VendorController@detail'); // 获取供应商详情 Route::post('order', 'app\store\controller\VendorController@createOrder'); // 创建订单 }); -})->middleware(['jwt']); \ No newline at end of file +})->middleware(['jwt']); + +Route::get('v1/store/login', 'app\store\controller\LoginController@index'); \ No newline at end of file diff --git a/Server/application/store/controller/LoginController.php b/Server/application/store/controller/LoginController.php index f507295a..ea364f4e 100644 --- a/Server/application/store/controller/LoginController.php +++ b/Server/application/store/controller/LoginController.php @@ -2,9 +2,11 @@ namespace app\store\controller; +use app\common\util\JwtUtil; use think\Db; +use think\Controller; -class LoginController extends BaseController +class LoginController extends Controller { public function index() { @@ -13,13 +15,26 @@ class LoginController extends BaseController return errorJson('缺少必要参数'); } - $user = Db::name('user')->alias('u') - ->join('device_user du','u.id = du.userId and u.companyId = du.companyId') - ->join('device d','du.deviceId = d.id and u.companyId = du.companyId') - ->where(['d.deviceImei' => $deviceId,'u.deleteTime' => 0,'du.deleteTime' => 0,'d.deleteTime'=> 0 ]) + $user = Db::name('users')->alias('u') + ->field('u.*') + ->join('device_user du', 'u.id = du.userId and u.companyId = du.companyId') + ->join('device d', 'du.deviceId = d.id and u.companyId = du.companyId') + ->where(['d.deviceImei' => $deviceId, 'u.deleteTime' => 0, 'du.deleteTime' => 0, 'd.deleteTime' => 0]) ->find(); + $member = array_merge($user, [ + 'lastLoginIp' => $this->request->ip(), + 'lastLoginTime' => time() + ]); - exit_data($user); + // 生成JWT令牌 + $token = JwtUtil::createToken($user, 86400 * 30); + $token_expired = time() + 86400 * 30; + $data = [ + 'member' => $member, + 'token' => $token, + 'token_expired' => $token_expired + ]; + return successJson($data, '登录成功'); } } \ No newline at end of file diff --git a/Store_vue/api/config/index.js b/Store_vue/api/config/index.js index 961630bf..29c6eba6 100644 --- a/Store_vue/api/config/index.js +++ b/Store_vue/api/config/index.js @@ -1,8 +1,8 @@ // API配置文件 // 基础配置 -export const BASE_URL = 'http://yishi.com' -//export const BASE_URL = 'https://ckbapi.quwanzhi.com' +//export const BASE_URL = 'http://yishi.com' +export const BASE_URL = 'https://ckbapi.quwanzhi.com' // 获取请求头 const getHeaders = (options = {}) => { diff --git a/Store_vue/api/modules/auth.js b/Store_vue/api/modules/auth.js index cd7c7f56..cee024a6 100644 --- a/Store_vue/api/modules/auth.js +++ b/Store_vue/api/modules/auth.js @@ -17,5 +17,17 @@ export const authApi = { deviceId: deviceId || '' // 设备ID(仅APP端有值) } }) + }, + + // 免密登录 + // @param {string} deviceId - 设备ID + noPasswordLogin: (deviceId) => { + return request({ + url: '/v1/store/login', + method: 'GET', + data: { + deviceId: deviceId || '' + } + }) } } \ No newline at end of file diff --git a/Store_vue/pages/login/index.vue b/Store_vue/pages/login/index.vue index 4c5eb2e9..29d345d8 100644 --- a/Store_vue/pages/login/index.vue +++ b/Store_vue/pages/login/index.vue @@ -61,6 +61,14 @@ 登录 + + + 免密登录 + + 联系我们 @@ -243,6 +251,66 @@ } }, + // 处理免密登录 + async handleNoPasswordLogin() { + // 检查设备ID是否存在 + if (!this.deviceId) { + uni.showToast({ + title: '获取设备信息失败,请重试', + icon: 'none' + }); + return; + } + + uni.showLoading({ + title: '免密登录中...', + mask: true + }); + + try { + // 调用免密登录API + const response = await authApi.noPasswordLogin(this.deviceId); + + console.log('免密登录响应:', response); + console.log('设备ID:', this.deviceId); + + if (response.code === 200) { + // 登录成功,缓存token信息 + const { token, member, token_expired } = response.data; + + // 存储token信息 + uni.setStorageSync('token', token); + uni.setStorageSync('member', JSON.stringify(member)); + uni.setStorageSync('token_expired', token_expired); + + uni.showToast({ + title: '免密登录成功', + icon: 'success' + }); + + // 登录成功后跳转到对话页面 + setTimeout(() => { + redirectToChat(); + }, 1500); + } else { + // 登录失败,显示错误信息 + uni.showToast({ + title: response.msg || '免密登录失败,请使用账号密码登录', + icon: 'none', + duration: 2000 + }); + } + } catch (err) { + console.error('免密登录失败:', err); + uni.showToast({ + title: '网络异常,请稍后重试', + icon: 'none' + }); + } finally { + uni.hideLoading(); + } + }, + // 打开协议 openAgreement(type) { uni.showToast({ @@ -371,6 +439,23 @@ background-color: #4080ff; } + .no-password-login-btn { + height: 44px; + line-height: 44px; + text-align: center; + background-color: #fff; + color: #4080ff; + border: 1px solid #4080ff; + border-radius: 22px; + margin: 10px 0 20px; + font-size: 16px; + transition: all 0.3s; + } + + .no-password-login-btn:active { + background-color: #f0f5ff; + } + .contact-us { text-align: center; color: #999;