index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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: '登录失败,请重试', 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: '头像上传失败', 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: '注册失败,请重试', 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. }
  254. }
  255. }
  256. </script>
  257. <style scoped>
  258. /* 基础容器 */
  259. .login-container {
  260. width: 100%;
  261. min-height: 100vh;
  262. background: #fff;
  263. position: relative;
  264. display: flex;
  265. flex-direction: column;
  266. }
  267. .gradient-bg {
  268. position: absolute;
  269. top: 0;
  270. left: 0;
  271. right: 0;
  272. height: 600rpx;
  273. background: linear-gradient(180deg, rgba(193, 0, 28, 0.12) 0%, rgba(255, 255, 255, 0) 100%);
  274. z-index: 1;
  275. }
  276. .content-wrapper {
  277. position: relative;
  278. z-index: 2;
  279. flex: 1;
  280. display: flex;
  281. flex-direction: column;
  282. padding: 0 80rpx;
  283. box-sizing: border-box;
  284. }
  285. .logo-section {
  286. display: flex;
  287. flex-direction: column;
  288. align-items: center;
  289. margin-top: 360rpx;
  290. margin-bottom: 120rpx;
  291. }
  292. .logo-outer {
  293. width: 200rpx;
  294. height: 200rpx;
  295. background: #fff;
  296. border-radius: 48rpx;
  297. 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);
  298. display: flex;
  299. align-items: center;
  300. justify-content: center;
  301. overflow: hidden;
  302. margin-bottom: 40rpx;
  303. }
  304. .logo-img {
  305. width: 100%;
  306. height: 100%;
  307. }
  308. .app-title {
  309. font-size: 48rpx;
  310. font-weight: bold;
  311. color: #1a1a1a;
  312. letter-spacing: 2rpx;
  313. }
  314. .app-subtitle {
  315. font-size: 26rpx;
  316. color: #999;
  317. margin-top: 10rpx;
  318. letter-spacing: 6rpx;
  319. }
  320. .main-btn {
  321. width: 100%;
  322. height: 100rpx;
  323. background: linear-gradient(135deg, #C1001C 0%, #FF4D4F 100%);
  324. border-radius: 50rpx;
  325. color: #fff;
  326. display: flex;
  327. align-items: center;
  328. justify-content: center;
  329. font-size: 32rpx;
  330. font-weight: bold;
  331. box-shadow: 0 12rpx 30rpx rgba(193, 0, 28, 0.2);
  332. border: none;
  333. margin-bottom: 40rpx;
  334. }
  335. .btn-icon {
  336. width: 48rpx;
  337. height: 48rpx;
  338. margin-right: 16rpx;
  339. }
  340. .agreement-text {
  341. font-size: 24rpx;
  342. color: #999;
  343. }
  344. .link {
  345. color: #C1001C;
  346. margin: 0 4rpx;
  347. font-weight: 500;
  348. }
  349. .footer-section {
  350. margin-top: auto;
  351. padding-bottom: 60rpx;
  352. text-align: center;
  353. font-size: 20rpx;
  354. color: #dcdcdc;
  355. }
  356. /* 弹窗通用基础 */
  357. .global-mask {
  358. position: fixed;
  359. top: 0;
  360. left: 0;
  361. right: 0;
  362. bottom: 0;
  363. background: rgba(0, 0, 0, 0.5);
  364. z-index: 998;
  365. }
  366. .center-card {
  367. position: fixed;
  368. top: 50%;
  369. left: 50%;
  370. transform: translate(-50%, -50%);
  371. width: 620rpx;
  372. background: #fff;
  373. border-radius: 32rpx;
  374. z-index: 1000;
  375. box-shadow: 0 30rpx 80rpx rgba(0, 0, 0, 0.15);
  376. padding: 50rpx 40rpx;
  377. display: flex;
  378. flex-direction: column;
  379. }
  380. .bottom-pop {
  381. position: fixed;
  382. bottom: 0;
  383. left: 0;
  384. right: 0;
  385. background: #fff;
  386. border-radius: 40rpx 40rpx 0 0;
  387. z-index: 1001;
  388. padding: 40rpx;
  389. padding-bottom: calc(50rpx + env(safe-area-inset-bottom));
  390. box-shadow: 0 -10rpx 40rpx rgba(0, 0, 0, 0.05);
  391. }
  392. /* 按钮对齐辅助 */
  393. button {
  394. display: flex !important;
  395. align-items: center !important;
  396. justify-content: center !important;
  397. padding: 0 !important;
  398. line-height: normal !important;
  399. }
  400. button::after {
  401. border: none;
  402. }
  403. /* 协议拦截弹窗 */
  404. .card-title {
  405. font-size: 38rpx;
  406. font-weight: bold;
  407. text-align: center;
  408. margin-bottom: 30rpx;
  409. }
  410. .card-body {
  411. font-size: 28rpx;
  412. color: #666;
  413. line-height: 1.6;
  414. text-align: center;
  415. margin-bottom: 50rpx;
  416. }
  417. .card-footer-btns {
  418. display: flex;
  419. gap: 24rpx;
  420. }
  421. .btn-item {
  422. flex: 1;
  423. height: 90rpx;
  424. border-radius: 45rpx;
  425. font-size: 30rpx;
  426. display: flex !important;
  427. align-items: center !important;
  428. justify-content: center !important;
  429. text-align: center;
  430. line-height: 90rpx;
  431. }
  432. .btn-item.cancel {
  433. background: #f8f8f8;
  434. color: #999;
  435. }
  436. .btn-item.agree {
  437. background: #C1001C;
  438. color: #fff;
  439. font-weight: bold;
  440. }
  441. /* 协议内容弹窗专项修复 */
  442. .p-pop-header {
  443. display: flex;
  444. justify-content: space-between;
  445. align-items: center;
  446. margin-bottom: 30rpx;
  447. }
  448. .p-pop-title {
  449. font-size: 36rpx;
  450. font-weight: bold;
  451. color: #1a1a1a;
  452. }
  453. .p-pop-close {
  454. font-size: 48rpx;
  455. color: #ccc;
  456. padding: 10rpx;
  457. }
  458. .p-pop-scroll {
  459. max-height: 55vh;
  460. margin-bottom: 30rpx;
  461. }
  462. .rich-text-wrapper {
  463. padding: 10rpx 0;
  464. color: #444;
  465. font-size: 28rpx;
  466. }
  467. .p-pop-footer {
  468. padding-top: 20rpx;
  469. }
  470. .p-pop-btn {
  471. width: 100%;
  472. height: 90rpx;
  473. background: #C1001C;
  474. color: #fff;
  475. border-radius: 45rpx;
  476. font-size: 30rpx;
  477. font-weight: bold;
  478. }
  479. /* 头像授权弹窗 */
  480. .pop-header-bar {
  481. display: flex;
  482. justify-content: space-between;
  483. align-items: center;
  484. margin-bottom: 60rpx;
  485. }
  486. .pop-cancel {
  487. font-size: 30rpx;
  488. color: #999;
  489. }
  490. .pop-main-title {
  491. font-size: 32rpx;
  492. font-weight: bold;
  493. }
  494. .pop-done {
  495. font-size: 30rpx;
  496. color: #C1001C;
  497. font-weight: bold;
  498. }
  499. .profile-edit-content {
  500. display: flex;
  501. flex-direction: column;
  502. align-items: center;
  503. }
  504. .avatar-wrapper-btn {
  505. width: 170rpx;
  506. height: 170rpx;
  507. border-radius: 85rpx;
  508. background: #f8f8f8;
  509. position: relative;
  510. margin-bottom: 24rpx;
  511. padding: 0 !important;
  512. overflow: visible;
  513. display: flex !important;
  514. align-items: center;
  515. justify-content: center;
  516. border: none;
  517. }
  518. .current-avatar {
  519. width: 100%;
  520. height: 100%;
  521. border-radius: 85rpx;
  522. border: 4rpx solid #fff;
  523. box-shadow: 0 4rpx 15rpx rgba(0, 0, 0, 0.05);
  524. }
  525. .camera-icon {
  526. position: absolute;
  527. bottom: 0;
  528. right: 0;
  529. background: #fff;
  530. width: 56rpx;
  531. height: 56rpx;
  532. border-radius: 28rpx;
  533. display: flex;
  534. align-items: center;
  535. justify-content: center;
  536. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.12);
  537. z-index: 5;
  538. }
  539. .camera-icon image {
  540. width: 30rpx;
  541. height: 30rpx;
  542. }
  543. .edit-hint {
  544. font-size: 24rpx;
  545. color: #999;
  546. margin-bottom: 70rpx;
  547. width: 100%;
  548. text-align: center;
  549. display: block;
  550. }
  551. .nickname-edit-box {
  552. width: 100%;
  553. display: flex;
  554. align-items: center;
  555. padding: 36rpx 0;
  556. border-top: 1rpx solid #f0f0f0;
  557. border-bottom: 1rpx solid #f0f0f0;
  558. margin-bottom: 40rpx;
  559. }
  560. .nickname-edit-box .label {
  561. width: 130rpx;
  562. font-size: 32rpx;
  563. }
  564. .nickname-input {
  565. flex: 1;
  566. font-size: 32rpx;
  567. }
  568. .notice-text {
  569. font-size: 24rpx;
  570. color: #bfbfbf;
  571. text-align: center;
  572. display: block;
  573. margin-bottom: 60rpx;
  574. }
  575. .confirm-btn-fixed {
  576. width: 100%;
  577. height: 96rpx;
  578. background: #C1001C;
  579. color: #fff;
  580. border-radius: 16rpx;
  581. font-size: 32rpx;
  582. font-weight: bold;
  583. }
  584. /* 手机号授权弹窗 */
  585. .p-header {
  586. display: flex;
  587. align-items: center;
  588. margin-bottom: 50rpx;
  589. }
  590. .p-mini-logo {
  591. width: 44rpx;
  592. height: 44rpx;
  593. border-radius: 8rpx;
  594. margin-right: 16rpx;
  595. }
  596. .p-app-name {
  597. font-size: 28rpx;
  598. color: #7f7f7f;
  599. }
  600. .p-title {
  601. font-size: 40rpx;
  602. font-weight: bold;
  603. color: #000;
  604. margin-bottom: 44rpx;
  605. display: block;
  606. }
  607. .p-phone-hint {
  608. font-size: 30rpx;
  609. color: #666;
  610. line-height: 1.5;
  611. display: block;
  612. margin-bottom: 60rpx;
  613. }
  614. .p-number-card {
  615. background: #fbfbfb;
  616. padding: 36rpx;
  617. border-radius: 20rpx;
  618. display: flex;
  619. justify-content: space-between;
  620. align-items: center;
  621. margin-bottom: 30rpx;
  622. border: 1rpx solid #f0f0f0;
  623. }
  624. .p-real-num {
  625. font-size: 36rpx;
  626. font-weight: bold;
  627. color: #1a1a1a;
  628. display: block;
  629. }
  630. .p-num-hint {
  631. font-size: 24rpx;
  632. color: #999;
  633. }
  634. .p-other-link {
  635. font-size: 28rpx;
  636. color: #576b95;
  637. display: block;
  638. margin-bottom: 60rpx;
  639. }
  640. .p-footer-btns {
  641. display: flex;
  642. gap: 30rpx;
  643. }
  644. .p-btn-fixed {
  645. flex: 1;
  646. height: 96rpx;
  647. border-radius: 16rpx;
  648. font-size: 32rpx;
  649. border: none;
  650. }
  651. .p-deny {
  652. background: #f2f2f2;
  653. color: #C1001C;
  654. }
  655. .p-allow {
  656. background: #C1001C;
  657. color: #fff;
  658. font-weight: bold;
  659. }
  660. </style>