index.vue 16 KB

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