index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. <template>
  2. <view class="login-container">
  3. <!-- 顶部高级渐变背景 -->
  4. <view class="gradient-bg"></view>
  5. <view class="content-wrapper">
  6. <!-- Logo 区域 -->
  7. <view class="logo-section">
  8. <view class="logo-outer">
  9. <image class="logo-img" :src="assets.logo" mode="aspectFill"></image>
  10. </view>
  11. <text class="app-title">ERP 智能下单系统</text>
  12. <text class="app-subtitle">简洁 · 高效 · 数字化管理</text>
  13. </view>
  14. <!-- 按钮区域 -->
  15. <view class="action-section">
  16. <button class="main-btn" @click="startLoginFlow">
  17. <image class="btn-icon" :src="assets.wechat" mode="aspectFit"></image>
  18. <text>授权手机号码登录</text>
  19. </button>
  20. <view class="agreement-box">
  21. <label class="checkbox-label" @click="toggleAgreed">
  22. <checkbox :checked="isAgreed" color="#C1001C" style="transform:scale(0.7)" />
  23. <text class="agreement-text">我已阅读并同意
  24. <text class="link" @click.stop="showProtocol('user')">《用户协议》</text> 与
  25. <text class="link" @click.stop="showProtocol('privacy')">《隐私政策》</text>
  26. </text>
  27. </label>
  28. </view>
  29. </view>
  30. <!-- 页脚 -->
  31. <view class="footer-section">
  32. <text>© 2026 ERP Order System. All Rights Reserved.</text>
  33. </view>
  34. </view>
  35. <!-- 全局遮罩 -->
  36. <view class="global-mask" v-if="activeModal" @click="closeAllModals"></view>
  37. <!-- 1. 协议拦截确认弹窗 -->
  38. <view class="confirm-modal center-card" v-if="activeModal === 'confirm'">
  39. <view class="card-title">服务协议提示</view>
  40. <view class="card-body">请您阅读并同意我们的协议内容,以便为您提供更安全的服务体验。</view>
  41. <view class="card-footer-btns">
  42. <view class="btn-item cancel" @click="activeModal = ''">拒绝</view>
  43. <view class="btn-item agree" @click="agreeAndClose">同意并继续</view>
  44. </view>
  45. </view>
  46. <!-- 2. 头像昵称授权弹窗 (原生能力适配) -->
  47. <view class="simulated-profile-pop bottom-pop" v-if="activeModal === 'profile'">
  48. <view class="pop-header-bar">
  49. <text class="pop-cancel" @click="activeModal = ''">取消</text>
  50. <text class="pop-main-title">获取头像昵称</text>
  51. <text class="pop-done" @click="activeModal = 'phone'">保存</text>
  52. </view>
  53. <view class="profile-edit-content">
  54. <view class="avatar-edit-box">
  55. <!-- 使用微信原生头像选择能力 -->
  56. <button class="avatar-wrapper-btn" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  57. <image class="current-avatar"
  58. :src="avatarPreviewUrl || 'https://img.icons8.com/color/144/user.png'"></image>
  59. <view class="camera-icon">
  60. <image src="https://img.icons8.com/ios-glyphs/30/999999/camera.png" mode="aspectFit">
  61. </image>
  62. </view>
  63. </button>
  64. <text class="edit-hint">点击修改头像</text>
  65. </view>
  66. <view class="nickname-edit-box">
  67. <text class="label">昵称</text>
  68. <!-- 使用微信原生昵称填写能力 -->
  69. <input class="nickname-input" type="nickname" :value="userName" placeholder="请输入昵称"
  70. @blur="onNicknameBlur" @input="onNicknameChange" />
  71. </view>
  72. <view class="auth-notice-box">
  73. <text class="notice-text">授权后,开发者将获得您的头像和昵称,用于展示您的个人资料。</text>
  74. </view>
  75. </view>
  76. <view class="bottom-action">
  77. <button class="confirm-btn-fixed" @click="goToPhoneAuth">确定</button>
  78. </view>
  79. </view>
  80. <!-- 3. 模拟手机号授权 -->
  81. <view class="phone-auth-pop bottom-pop" v-if="activeModal === 'phone'">
  82. <view class="p-header">
  83. <image class="p-mini-logo" :src="assets.logo" mode="aspectFill"></image>
  84. <text class="p-app-name">ERP 智能下单系统 申请</text>
  85. </view>
  86. <view class="p-body">
  87. <text class="p-title">获取您的手机号</text>
  88. <text class="p-phone-hint">是否允许我们获取您的手机号,用于登录和订单通知?</text>
  89. </view>
  90. <view class="p-footer-btns">
  91. <button class="p-btn-fixed p-deny" @click="activeModal = ''">拒绝</button>
  92. <button class="p-btn-fixed p-allow" open-type="getPhoneNumber"
  93. @getphonenumber="handleGetPhoneNumber">允许</button>
  94. </view>
  95. </view>
  96. <!-- 4. 协议富文本弹窗 (样式专项修复) -->
  97. <view class="protocol-modal center-card" v-if="activeModal === 'protocol'">
  98. <view class="p-pop-header">
  99. <text class="p-pop-title">{{ currentProtocol.title }}</text>
  100. <text class="p-pop-close" @click="activeModal = ''">×</text>
  101. </view>
  102. <scroll-view scroll-y class="p-pop-scroll">
  103. <view class="rich-text-wrapper">
  104. <rich-text :nodes="currentProtocol.content"></rich-text>
  105. </view>
  106. </scroll-view>
  107. <view class="p-pop-footer">
  108. <button class="p-pop-btn" @click="activeModal = ''">我已了解</button>
  109. </view>
  110. </view>
  111. </view>
  112. </template>
  113. <script>
  114. import assets from '@/utils/assets.js';
  115. import { getAgreement } from '@/api/system/agreement.js';
  116. import { wechatLogin, getWechatPhone, wechatRegister } from '@/api/auth/index.js';
  117. import { uploadFile } from '@/api/resource/oss.js';
  118. export default {
  119. data() {
  120. return {
  121. assets, isAgreed: false, activeModal: '',
  122. avatarOssId: null, avatarPreviewUrl: '', userName: '微信用户',
  123. currentProtocol: { title: '', content: '' },
  124. protocols: {
  125. user: { title: '', content: '' },
  126. privacy: { title: '', content: '' }
  127. },
  128. openId: '',
  129. unionId: '',
  130. phoneNumber: ''
  131. }
  132. },
  133. methods: {
  134. toggleAgreed() { this.isAgreed = !this.isAgreed; },
  135. startLoginFlow() {
  136. if (!this.isAgreed) this.activeModal = 'confirm';
  137. else this.performLogin();
  138. },
  139. agreeAndClose() {
  140. this.isAgreed = true;
  141. this.activeModal = '';
  142. },
  143. async performLogin() {
  144. try {
  145. uni.showLoading({ title: '登录中...' });
  146. const loginRes = await new Promise((resolve, reject) => {
  147. wx.login({
  148. success: resolve,
  149. fail: reject
  150. });
  151. });
  152. if (!loginRes.code) {
  153. uni.hideLoading();
  154. uni.showToast({ title: '获取登录凭证失败', icon: 'none' });
  155. return;
  156. }
  157. const res = await wechatLogin({ loginCode: loginRes.code });
  158. uni.hideLoading();
  159. if (res.data && res.data.access_token) {
  160. uni.setStorageSync('token', res.data.access_token);
  161. uni.setStorageSync('isLogin', true);
  162. uni.showToast({ title: '登录成功', icon: 'success' });
  163. setTimeout(() => {
  164. uni.reLaunch({ url: '/pages/order/index' });
  165. }, 1000);
  166. } else if (res.data && res.data.openid) {
  167. this.openId = res.data.openid;
  168. this.unionId = res.data.unionid || '';
  169. this.activeModal = 'profile';
  170. } else {
  171. uni.showToast({ title: '登录失败', icon: 'none' });
  172. }
  173. } catch (error) {
  174. uni.hideLoading();
  175. console.error('登录错误:', error);
  176. uni.showToast({ title: error || '登录失败', icon: 'none' });
  177. }
  178. },
  179. async onChooseAvatar(e) {
  180. const tempPath = e.detail.avatarUrl;
  181. console.log('[微信信息] 头像临时路径:', tempPath);
  182. this.avatarPreviewUrl = tempPath;
  183. try {
  184. uni.showLoading({ title: '上传头像...' });
  185. const res = await uploadFile(tempPath);
  186. uni.hideLoading();
  187. this.avatarOssId = res.ossId;
  188. this.avatarPreviewUrl = res.url;
  189. console.log('[微信信息] 头像OSS上传成功, ossId:', this.avatarOssId);
  190. } catch (err) {
  191. uni.hideLoading();
  192. console.error('[微信信息] 头像上传失败:', err);
  193. uni.showToast({ title: err || '头像上传失败', icon: 'none' });
  194. }
  195. },
  196. onNicknameBlur(e) {
  197. this.userName = e.detail.value;
  198. console.log('[微信信息] 昵称(blur):', this.userName);
  199. },
  200. onNicknameChange(e) {
  201. this.userName = e.detail.value;
  202. console.log('[微信信息] 昵称(input):', this.userName);
  203. },
  204. async goToPhoneAuth() {
  205. this.phoneNumber = '';
  206. this.activeModal = 'phone';
  207. },
  208. async handleGetPhoneNumber(e) {
  209. if (e.detail.errMsg !== 'getPhoneNumber:ok') {
  210. uni.showToast({ title: '获取手机号失败,请重试', icon: 'none' });
  211. return;
  212. }
  213. try {
  214. uni.showLoading({ title: '获取手机号中...' });
  215. const phoneRes = await getWechatPhone({
  216. phoneCode: e.detail.code,
  217. openId: this.openId
  218. });
  219. uni.hideLoading();
  220. this.phoneNumber = phoneRes.data;
  221. uni.showLoading({ title: '注册中...' });
  222. const registerRes = await wechatRegister({
  223. openId: this.openId,
  224. unionId: this.unionId,
  225. phone: this.phoneNumber,
  226. nickname: this.userName,
  227. avatar: this.avatarOssId
  228. });
  229. uni.hideLoading();
  230. this.performLogin();
  231. } catch (error) {
  232. uni.hideLoading();
  233. console.error('注册错误:', error);
  234. uni.showToast({ title: error || '注册失败', icon: 'none' });
  235. }
  236. },
  237. showProtocol(type) {
  238. this.currentProtocol = this.protocols[type];
  239. this.activeModal = 'protocol';
  240. },
  241. closeAllModals() { this.activeModal = ''; }
  242. },
  243. async mounted() {
  244. try {
  245. const [userRes, privacyRes] = await Promise.all([
  246. getAgreement(1),
  247. getAgreement(2)
  248. ]);
  249. this.protocols.user = { title: userRes.data.title, content: userRes.data.content };
  250. this.protocols.privacy = { title: privacyRes.data.title, content: privacyRes.data.content };
  251. } catch (e) {
  252. console.error('[协议] 加载失败', e);
  253. uni.showToast({ title: e || '加载协议失败', icon: 'none' });
  254. }
  255. }
  256. }
  257. </script>
  258. <style scoped>
  259. /* 基础容器 */
  260. .login-container {
  261. width: 100%;
  262. min-height: 100vh;
  263. background: #fff;
  264. position: relative;
  265. display: flex;
  266. flex-direction: column;
  267. }
  268. .gradient-bg {
  269. position: absolute;
  270. top: 0;
  271. left: 0;
  272. right: 0;
  273. height: 600rpx;
  274. background: linear-gradient(180deg, rgba(193, 0, 28, 0.12) 0%, rgba(255, 255, 255, 0) 100%);
  275. z-index: 1;
  276. }
  277. .content-wrapper {
  278. position: relative;
  279. z-index: 2;
  280. flex: 1;
  281. display: flex;
  282. flex-direction: column;
  283. padding: 0 80rpx;
  284. box-sizing: border-box;
  285. }
  286. .logo-section {
  287. display: flex;
  288. flex-direction: column;
  289. align-items: center;
  290. margin-top: 360rpx;
  291. margin-bottom: 120rpx;
  292. }
  293. .logo-outer {
  294. width: 200rpx;
  295. height: 200rpx;
  296. background: #fff;
  297. border-radius: 48rpx;
  298. box-shadow: 0 40rpx 80rpx rgba(193, 0, 28, 0.35), 0 10rpx 30rpx rgba(0, 0, 0, 0.1), inset 0 4rpx 10rpx rgba(255, 255, 255, 0.8);
  299. display: flex;
  300. align-items: center;
  301. justify-content: center;
  302. overflow: hidden;
  303. margin-bottom: 40rpx;
  304. }
  305. .logo-img {
  306. width: 100%;
  307. height: 100%;
  308. }
  309. .app-title {
  310. font-size: 48rpx;
  311. font-weight: bold;
  312. color: #1a1a1a;
  313. letter-spacing: 2rpx;
  314. }
  315. .app-subtitle {
  316. font-size: 26rpx;
  317. color: #999;
  318. margin-top: 10rpx;
  319. letter-spacing: 6rpx;
  320. }
  321. .main-btn {
  322. width: 100%;
  323. height: 100rpx;
  324. background: linear-gradient(135deg, #C1001C 0%, #FF4D4F 100%);
  325. border-radius: 50rpx;
  326. color: #fff;
  327. display: flex;
  328. align-items: center;
  329. justify-content: center;
  330. font-size: 32rpx;
  331. font-weight: bold;
  332. box-shadow: 0 12rpx 30rpx rgba(193, 0, 28, 0.2);
  333. border: none;
  334. margin-bottom: 40rpx;
  335. }
  336. .btn-icon {
  337. width: 48rpx;
  338. height: 48rpx;
  339. margin-right: 16rpx;
  340. }
  341. .agreement-text {
  342. font-size: 24rpx;
  343. color: #999;
  344. }
  345. .link {
  346. color: #C1001C;
  347. margin: 0 4rpx;
  348. font-weight: 500;
  349. }
  350. .footer-section {
  351. margin-top: auto;
  352. padding-bottom: 60rpx;
  353. text-align: center;
  354. font-size: 20rpx;
  355. color: #dcdcdc;
  356. }
  357. /* 弹窗通用基础 */
  358. .global-mask {
  359. position: fixed;
  360. top: 0;
  361. left: 0;
  362. right: 0;
  363. bottom: 0;
  364. background: rgba(0, 0, 0, 0.5);
  365. z-index: 998;
  366. }
  367. .center-card {
  368. position: fixed;
  369. top: 50%;
  370. left: 50%;
  371. transform: translate(-50%, -50%);
  372. width: 620rpx;
  373. background: #fff;
  374. border-radius: 32rpx;
  375. z-index: 1000;
  376. box-shadow: 0 30rpx 80rpx rgba(0, 0, 0, 0.15);
  377. padding: 50rpx 40rpx;
  378. display: flex;
  379. flex-direction: column;
  380. }
  381. .bottom-pop {
  382. position: fixed;
  383. bottom: 0;
  384. left: 0;
  385. right: 0;
  386. background: #fff;
  387. border-radius: 40rpx 40rpx 0 0;
  388. z-index: 1001;
  389. padding: 40rpx;
  390. padding-bottom: calc(50rpx + env(safe-area-inset-bottom));
  391. box-shadow: 0 -10rpx 40rpx rgba(0, 0, 0, 0.05);
  392. }
  393. /* 按钮对齐辅助 */
  394. button {
  395. display: flex !important;
  396. align-items: center !important;
  397. justify-content: center !important;
  398. padding: 0 !important;
  399. line-height: normal !important;
  400. }
  401. button::after {
  402. border: none;
  403. }
  404. /* 协议拦截弹窗 */
  405. .card-title {
  406. font-size: 38rpx;
  407. font-weight: bold;
  408. text-align: center;
  409. margin-bottom: 30rpx;
  410. }
  411. .card-body {
  412. font-size: 28rpx;
  413. color: #666;
  414. line-height: 1.6;
  415. text-align: center;
  416. margin-bottom: 50rpx;
  417. }
  418. .card-footer-btns {
  419. display: flex;
  420. gap: 24rpx;
  421. }
  422. .btn-item {
  423. flex: 1;
  424. height: 90rpx;
  425. border-radius: 45rpx;
  426. font-size: 30rpx;
  427. display: flex !important;
  428. align-items: center !important;
  429. justify-content: center !important;
  430. text-align: center;
  431. line-height: 90rpx;
  432. }
  433. .btn-item.cancel {
  434. background: #f8f8f8;
  435. color: #999;
  436. }
  437. .btn-item.agree {
  438. background: #C1001C;
  439. color: #fff;
  440. font-weight: bold;
  441. }
  442. /* 协议内容弹窗专项修复 */
  443. .p-pop-header {
  444. display: flex;
  445. justify-content: space-between;
  446. align-items: center;
  447. margin-bottom: 30rpx;
  448. }
  449. .p-pop-title {
  450. font-size: 36rpx;
  451. font-weight: bold;
  452. color: #1a1a1a;
  453. }
  454. .p-pop-close {
  455. font-size: 48rpx;
  456. color: #ccc;
  457. padding: 10rpx;
  458. }
  459. .p-pop-scroll {
  460. max-height: 55vh;
  461. margin-bottom: 30rpx;
  462. }
  463. .rich-text-wrapper {
  464. padding: 10rpx 0;
  465. color: #444;
  466. font-size: 28rpx;
  467. }
  468. .p-pop-footer {
  469. padding-top: 20rpx;
  470. }
  471. .p-pop-btn {
  472. width: 100%;
  473. height: 90rpx;
  474. background: #C1001C;
  475. color: #fff;
  476. border-radius: 45rpx;
  477. font-size: 30rpx;
  478. font-weight: bold;
  479. }
  480. /* 头像授权弹窗 */
  481. .pop-header-bar {
  482. display: flex;
  483. justify-content: space-between;
  484. align-items: center;
  485. margin-bottom: 60rpx;
  486. }
  487. .pop-cancel {
  488. font-size: 30rpx;
  489. color: #999;
  490. }
  491. .pop-main-title {
  492. font-size: 32rpx;
  493. font-weight: bold;
  494. }
  495. .pop-done {
  496. font-size: 30rpx;
  497. color: #C1001C;
  498. font-weight: bold;
  499. }
  500. .profile-edit-content {
  501. display: flex;
  502. flex-direction: column;
  503. align-items: center;
  504. }
  505. .avatar-wrapper-btn {
  506. width: 170rpx;
  507. height: 170rpx;
  508. border-radius: 85rpx;
  509. background: #f8f8f8;
  510. position: relative;
  511. margin-bottom: 24rpx;
  512. padding: 0 !important;
  513. overflow: visible;
  514. display: flex !important;
  515. align-items: center;
  516. justify-content: center;
  517. border: none;
  518. }
  519. .current-avatar {
  520. width: 100%;
  521. height: 100%;
  522. border-radius: 85rpx;
  523. border: 4rpx solid #fff;
  524. box-shadow: 0 4rpx 15rpx rgba(0, 0, 0, 0.05);
  525. }
  526. .camera-icon {
  527. position: absolute;
  528. bottom: 0;
  529. right: 0;
  530. background: #fff;
  531. width: 56rpx;
  532. height: 56rpx;
  533. border-radius: 28rpx;
  534. display: flex;
  535. align-items: center;
  536. justify-content: center;
  537. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.12);
  538. z-index: 5;
  539. }
  540. .camera-icon image {
  541. width: 30rpx;
  542. height: 30rpx;
  543. }
  544. .edit-hint {
  545. font-size: 24rpx;
  546. color: #999;
  547. margin-bottom: 70rpx;
  548. width: 100%;
  549. text-align: center;
  550. display: block;
  551. }
  552. .nickname-edit-box {
  553. width: 100%;
  554. display: flex;
  555. align-items: center;
  556. padding: 36rpx 0;
  557. border-top: 1rpx solid #f0f0f0;
  558. border-bottom: 1rpx solid #f0f0f0;
  559. margin-bottom: 40rpx;
  560. }
  561. .nickname-edit-box .label {
  562. width: 130rpx;
  563. font-size: 32rpx;
  564. }
  565. .nickname-input {
  566. flex: 1;
  567. font-size: 32rpx;
  568. }
  569. .notice-text {
  570. font-size: 24rpx;
  571. color: #bfbfbf;
  572. text-align: center;
  573. display: block;
  574. margin-bottom: 60rpx;
  575. }
  576. .confirm-btn-fixed {
  577. width: 100%;
  578. height: 96rpx;
  579. background: #C1001C;
  580. color: #fff;
  581. border-radius: 16rpx;
  582. font-size: 32rpx;
  583. font-weight: bold;
  584. }
  585. /* 手机号授权弹窗 */
  586. .p-header {
  587. display: flex;
  588. align-items: center;
  589. margin-bottom: 50rpx;
  590. }
  591. .p-mini-logo {
  592. width: 44rpx;
  593. height: 44rpx;
  594. border-radius: 8rpx;
  595. margin-right: 16rpx;
  596. }
  597. .p-app-name {
  598. font-size: 28rpx;
  599. color: #7f7f7f;
  600. }
  601. .p-title {
  602. font-size: 40rpx;
  603. font-weight: bold;
  604. color: #000;
  605. margin-bottom: 44rpx;
  606. display: block;
  607. }
  608. .p-phone-hint {
  609. font-size: 30rpx;
  610. color: #666;
  611. line-height: 1.5;
  612. display: block;
  613. margin-bottom: 60rpx;
  614. }
  615. .p-number-card {
  616. background: #fbfbfb;
  617. padding: 36rpx;
  618. border-radius: 20rpx;
  619. display: flex;
  620. justify-content: space-between;
  621. align-items: center;
  622. margin-bottom: 30rpx;
  623. border: 1rpx solid #f0f0f0;
  624. }
  625. .p-real-num {
  626. font-size: 36rpx;
  627. font-weight: bold;
  628. color: #1a1a1a;
  629. display: block;
  630. }
  631. .p-num-hint {
  632. font-size: 24rpx;
  633. color: #999;
  634. }
  635. .p-other-link {
  636. font-size: 28rpx;
  637. color: #576b95;
  638. display: block;
  639. margin-bottom: 60rpx;
  640. }
  641. .p-footer-btns {
  642. display: flex;
  643. gap: 30rpx;
  644. }
  645. .p-btn-fixed {
  646. flex: 1;
  647. height: 96rpx;
  648. border-radius: 16rpx;
  649. font-size: 32rpx;
  650. border: none;
  651. }
  652. .p-deny {
  653. background: #f2f2f2;
  654. color: #C1001C;
  655. }
  656. .p-allow {
  657. background: #C1001C;
  658. color: #fff;
  659. font-weight: bold;
  660. }
  661. </style>