index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. <template>
  2. <view class="container">
  3. <!-- 上半部分:轮播图区域 -->
  4. <view class="top-section">
  5. <swiper class="swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000"
  6. :circular="true" indicator-active-color="#1B64F0" indicator-color="rgba(255, 255, 255, 0.6)"
  7. indicator-class="swiper-indicator" active-class="swiper-indicator-active">
  8. <swiper-item v-for="(item, index) in swiperList" :key="index" @click="handleBannerClick(item)">
  9. <view class="swiper-item">
  10. <image class="swiper-img" :src="item.imageUrl" mode="aspectFill" />
  11. </view>
  12. </swiper-item>
  13. </swiper>
  14. </view>
  15. <view class="search-section">
  16. <view class="search-input-wrapper">
  17. <image class="search-icon" src="@/static/img/search.png" />
  18. <input class="search-input" placeholder="请输入要查询的运单号" placeholder-class="placeholder-style"
  19. @focus="onInputFocus" @blur="onInputBlur" v-model="trackingNumber" />
  20. <view class="search-btn" @click="handleSearch">
  21. 搜索
  22. </view>
  23. </view>
  24. </view>
  25. <view class="btn-container">
  26. <view class="btn-item" @click="handleExpress('1')">
  27. <image class="button-icon" src="/static/img/index-un-time.png" />
  28. <view class="button-right">
  29. <view class="button-title">瑞鲸速达(京东)</view>
  30. <view class="button-desc">下单当日取件</view>
  31. </view>
  32. </view>
  33. <view class="btn-item" @click="showExpressDialog">
  34. <image class="button-icon" src="/static/img/index-personal.png" />
  35. <view class="button-right">
  36. <view class="button-title">个人寄件</view>
  37. <view class="button-desc">支持顺丰和京东</view>
  38. </view>
  39. </view>
  40. </view>
  41. <!-- 使用 u-popup 弹框组件(个人寄件) -->
  42. <PersonalExpressDialog :visible="showDialog" @update:visible="showDialog = $event"
  43. @select="handleExpressSelect" />
  44. <!-- ========== 新增:隐私协议弹框 ========== -->
  45. <u-popup :show="showPrivacyDialog" mode="center" :round="10" :closeable="false" :safeAreaInsetBottom="false">
  46. <view class="privacy-dialog">
  47. <view class="title">温馨提示</view>
  48. <view class="content">
  49. 欢迎使用本小程序。在使用我们的服务前,请您仔细阅读并同意以下协议:
  50. </view>
  51. <view class="protocol-links">
  52. <text class="link" @click="goToProtocol('user')">《用户协议》</text>
  53. <text class="and">与</text>
  54. <text class="link" @click="goToProtocol('privacy')">《隐私协议》</text>
  55. </view>
  56. <view class="content">
  57. 点击“同意”即表示您已阅读并同意上述协议的全部条款。
  58. </view>
  59. <view class="btn-group">
  60. <button class="btn reject" @click="onReject">拒绝</button>
  61. <button class="btn agree" @click="onAgree">同意</button>
  62. </view>
  63. </view>
  64. </u-popup>
  65. <!-- ========== 新增结束 ========== -->
  66. </view>
  67. </template>
  68. <script setup>
  69. import {
  70. ref,
  71. onMounted
  72. } from 'vue'
  73. import {
  74. onShow
  75. } from '@dcloudio/uni-app'
  76. // 导入 u-popup 弹框组件
  77. import PersonalExpressDialog from './components/PersonalExpressDialog.vue'
  78. import {
  79. bannerList
  80. } from '../../api/user'
  81. import {
  82. checkLoginShowModal,
  83. quickLogin
  84. } from "@/utils/util.js";
  85. // ========== 新增:隐私协议相关常量和方法 ==========
  86. // 协议远程地址(请替换为实际线上地址)
  87. const USER_PROTOCOL_URL = 'https://rjsd.mychery.com/user_agreement.html'
  88. const PRIVACY_PROTOCOL_URL = 'https://rjsd.mychery.com/privacy_policy.html'
  89. // 控制协议弹框显示
  90. const showPrivacyDialog = ref(false)
  91. /**
  92. * 显示协议弹框
  93. */
  94. function showPrivacyModal() {
  95. showPrivacyDialog.value = true
  96. }
  97. /**
  98. * 关闭弹框
  99. */
  100. function closeDialog() {
  101. showPrivacyDialog.value = false
  102. }
  103. /**
  104. * 跳转到协议详情页(使用 WebView)
  105. * @param {string} type 'user' 或 'privacy'
  106. */
  107. function goToProtocol(type) {
  108. const url = type === 'user' ? USER_PROTOCOL_URL : PRIVACY_PROTOCOL_URL
  109. uni.navigateTo({
  110. url: `/pages/webView/webView?url=${encodeURIComponent(url)}`
  111. })
  112. }
  113. /**
  114. * 用户点击“同意”
  115. */
  116. function onAgree() {
  117. try {
  118. uni.setStorageSync('privacyAgreed', true)
  119. closeDialog()
  120. } catch (e) {
  121. console.error('存储失败', e)
  122. uni.showToast({ title: '操作失败,请重试', icon: 'none' })
  123. }
  124. }
  125. /**
  126. * 用户点击“拒绝”
  127. */
  128. function onReject() {
  129. closeDialog()
  130. uni.exitMiniProgram({
  131. success: function() {
  132. console.log('退出小程序成功');
  133. },
  134. fail: function(err) {
  135. console.log('退出小程序失败', err);
  136. uni.showToast({
  137. title: '无法退出,请同意协议',
  138. icon: 'none'
  139. })
  140. // 重新弹出协议框
  141. setTimeout(() => {
  142. showPrivacyModal()
  143. }, 300)
  144. }
  145. })
  146. }
  147. // ========== 新增结束 ==========
  148. const showDialog = ref(false)
  149. // 轮播图数据
  150. const swiperList = ref([])
  151. const trackingNumber = ref('')
  152. const isInputFocused = ref(false)
  153. onShow(() => {
  154. getBannerList()
  155. // ========== 新增:每次显示首页时检查协议状态 ==========
  156. try {
  157. const agreed = uni.getStorageSync('privacyAgreed')
  158. if (!agreed) {
  159. // 首次使用或未同意,显示协议弹框
  160. showPrivacyModal()
  161. }
  162. } catch (error) {
  163. console.error('读取存储失败', error)
  164. showPrivacyModal()
  165. }
  166. // ========== 新增结束 ==========
  167. })
  168. const getBannerList = () => {
  169. bannerList().then(res => {
  170. if (res.code == 200) {
  171. swiperList.value = res.data
  172. }
  173. }, {})
  174. }
  175. const showExpressDialog = () => {
  176. console.log('显示个人寄件弹框')
  177. showDialog.value = true
  178. }
  179. const handleExpressSelect = (company) => {
  180. // uni.showToast({
  181. // title: `已选择${company}物流`,
  182. // icon: 'success',
  183. // duration: 1500
  184. // })
  185. }
  186. const handleExpress = async (company) => {
  187. if (!await checkLoginShowModal()) return;
  188. uni.navigateTo({
  189. url: `/pages/order/create_order?product=${company}`
  190. })
  191. }
  192. const handleBannerClick = (item) => {
  193. // if (!item.linkUrl) {
  194. // // uni.showToast({ title: '暂无跳转链接', icon: 'none' });
  195. // return;
  196. // }
  197. // if (item.linkUrl.startsWith('http://') || item.linkUrl.startsWith('https://')) {
  198. // uni.navigateTo({
  199. // url: `/pages/webView/webView?url=${encodeURIComponent(item.linkUrl)}`
  200. // })
  201. // } else {
  202. // uni.showToast({ title: '链接格式不支持', icon: 'none' })
  203. // }
  204. };
  205. const onInputFocus = () => {
  206. isInputFocused.value = true
  207. }
  208. const onInputBlur = () => {
  209. isInputFocused.value = false
  210. }
  211. const handleSearch = async () => {
  212. if (!await checkLoginShowModal()) return;
  213. if (!trackingNumber.value.trim()) {
  214. uni.showToast({
  215. title: '请输入运单号',
  216. icon: 'none'
  217. })
  218. return
  219. }
  220. uni.navigateTo({
  221. url:'/pages/logistics/index?orderNo=' + trackingNumber.value.trim()
  222. })
  223. return
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .container {
  228. display: flex;
  229. flex-direction: column;
  230. height: 100vh;
  231. background-color: #F5F7FA;
  232. }
  233. .top-section {
  234. height: 563rpx;
  235. position: relative;
  236. }
  237. .swiper {
  238. width: 100%;
  239. height: 100%;
  240. position: relative;
  241. }
  242. .swiper-item {
  243. width: 100%;
  244. height: 100%;
  245. position: relative;
  246. }
  247. .swiper-img {
  248. width: 100%;
  249. height: 100%;
  250. object-fit: cover;
  251. }
  252. /* 自定义指示点样式 - 通过定位调整位置 */
  253. /* 方法一:调整整个指示器容器的位置 */
  254. /* 注意:在不同平台可能需要使用不同的选择器 */
  255. /* 微信小程序 */
  256. ::v-deep .wx-swiper-dots {
  257. bottom: 80rpx !important;
  258. /* 调整指示器容器的位置 */
  259. display: flex !important;
  260. justify-content: center !important;
  261. align-items: center !important;
  262. }
  263. /* H5平台 */
  264. ::v-deep .uni-swiper-dots {
  265. bottom: 80rpx !important;
  266. /* 调整指示器容器的位置 */
  267. display: flex !important;
  268. justify-content: center !important;
  269. align-items: center !important;
  270. }
  271. /* 方法二:直接修改指示点样式,通过调整父容器样式 */
  272. .swiper-indicator {
  273. width: 8rpx !important;
  274. height: 8rpx !important;
  275. border-radius: 50% !important;
  276. background: rgba(255, 255, 255, 0.6) !important;
  277. margin: 0 4rpx !important;
  278. }
  279. .swiper-indicator-active {
  280. width: 32rpx !important;
  281. height: 8rpx !important;
  282. background: #1B64F0 !important;
  283. border-radius: 4rpx !important;
  284. }
  285. /* 方法三:如果上述方法都不生效,可以使用绝对定位自定义指示器 */
  286. .custom-indicator {
  287. position: absolute;
  288. left: 0;
  289. right: 0;
  290. bottom: 80rpx;
  291. /* 调整指示器的垂直位置 */
  292. z-index: 10;
  293. display: flex;
  294. justify-content: center;
  295. align-items: center;
  296. }
  297. .custom-indicator-dot {
  298. width: 8rpx;
  299. height: 8rpx;
  300. border-radius: 50%;
  301. background: rgba(255, 255, 255, 0.6);
  302. margin: 0 4rpx;
  303. transition: all 0.3s ease;
  304. }
  305. .custom-indicator-dot.active {
  306. width: 32rpx;
  307. height: 8rpx;
  308. background: #1B64F0;
  309. border-radius: 4rpx;
  310. }
  311. /* 搜索区域 */
  312. .search-section {
  313. position: relative;
  314. top: -40rpx;
  315. width: 100%;
  316. padding: 0 20rpx;
  317. display: flex;
  318. flex-direction: column;
  319. align-items: center;
  320. .search-input-wrapper {
  321. width: 100%;
  322. height: 88rpx;
  323. background: #FFFFFF;
  324. border-radius: 44rpx;
  325. font-size: 28rpx;
  326. color: #333;
  327. border: 4rpx solid #1B64F0;
  328. padding: 6rpx;
  329. display: flex;
  330. justify-content: center;
  331. justify-items: center;
  332. align-items: center;
  333. .search-icon {
  334. width: 40rpx;
  335. height: 40rpx;
  336. margin-left: 18rpx;
  337. }
  338. .search-input {
  339. flex: 1;
  340. margin-left: 8rpx;
  341. margin-right: 8rpx;
  342. }
  343. .placeholder-style {
  344. color: #999999;
  345. }
  346. .search-btn {
  347. width: 160rpx;
  348. height: 76rpx;
  349. background: #1B64F0;
  350. border-radius: 38rpx;
  351. font-weight: 400;
  352. font-size: 32rpx;
  353. color: #FFFFFF;
  354. line-height: 76rpx;
  355. text-align: center;
  356. font-style: normal;
  357. }
  358. }
  359. }
  360. .btn-container {
  361. display: flex;
  362. flex-wrap: wrap;
  363. justify-content: space-between;
  364. padding: 0rpx 20rpx;
  365. .btn-item {
  366. width: 339rpx;
  367. height: 172rpx;
  368. background: #FFFFFF;
  369. box-shadow: 0rpx 4rpx 16rpx 0rpx rgba(27, 100, 240, 0.08), 0rpx 0rpx 8rpx 0rpx rgba(27, 100, 240, 0.08);
  370. border-radius: 32rpx;
  371. border: 2rpx solid #FFFFFF;
  372. display: flex;
  373. justify-content: center;
  374. align-items: center;
  375. padding: 20rpx 0rpx 20rpx 20rpx;
  376. margin-bottom: 32rpx;
  377. .button-icon {
  378. width: 88rpx;
  379. height: 88rpx;
  380. }
  381. .button-right {
  382. display: flex;
  383. flex-direction: column;
  384. flex: 1;
  385. margin-left: 16rpx;
  386. .button-title {
  387. height: 48rpx;
  388. line-height: 48rpx;
  389. font-size: 28rpx;
  390. font-weight: bold;
  391. color: #333;
  392. flex-shrink: 0;
  393. }
  394. .button-desc {
  395. height: 44rpx;
  396. line-height: 44rpx;
  397. font-size: 24rpx;
  398. color: #666;
  399. margin-top: 8rpx;
  400. }
  401. }
  402. }
  403. }
  404. .privacy-dialog {
  405. width: 600rpx;
  406. padding: 40rpx 30rpx;
  407. background-color: #fff;
  408. border-radius: 20rpx;
  409. box-sizing: border-box;
  410. .title {
  411. font-size: 36rpx;
  412. font-weight: bold;
  413. text-align: center;
  414. margin-bottom: 30rpx;
  415. color: #333;
  416. }
  417. .content {
  418. font-size: 28rpx;
  419. color: #666;
  420. line-height: 1.6;
  421. margin-bottom: 20rpx;
  422. }
  423. .protocol-links {
  424. display: flex;
  425. align-items: center;
  426. justify-content: center;
  427. margin: 20rpx 0;
  428. font-size: 30rpx;
  429. .link {
  430. color: #1B64F0;
  431. // text-decoration: underline;
  432. padding: 0 10rpx;
  433. }
  434. .and {
  435. color: #666;
  436. }
  437. }
  438. .btn-group {
  439. display: flex;
  440. justify-content: space-between;
  441. margin-top: 40rpx;
  442. .btn {
  443. flex: 1;
  444. height: 80rpx;
  445. line-height: 80rpx;
  446. text-align: center;
  447. border-radius: 40rpx;
  448. font-size: 30rpx;
  449. margin: 0 15rpx;
  450. &.reject {
  451. background-color: #f5f5f5;
  452. color: #999;
  453. border: 1px solid #ddd;
  454. }
  455. &.agree {
  456. background-color: #1B64F0;
  457. color: #fff;
  458. border: none;
  459. }
  460. }
  461. }
  462. }
  463. </style>