index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <!-- 首页 -->
  3. <view class="content">
  4. <!-- 顶部 -->
  5. <image :src="getFileUrl('/static/demo.png')" mode="aspectFill" class="top-img"></image>
  6. <!-- 内容 -->
  7. <view class="content-box">
  8. <view class="shop-info">
  9. <image :src="getFileUrl('img/icon/shop.png')" mode="aspectFill" class="shop-img"></image>
  10. <view class="shop-name">店铺名称</view>
  11. </view>
  12. <!-- 登录卡片 -->
  13. <view class='login-card' v-if="!userStore.getToken">
  14. <view class="login-card-left">
  15. <view class="welcome-title">欢迎来到xxx店铺</view>
  16. <view class="welcome-desc">注册登录即可体验更好的服务</view>
  17. <view class="login-btn" hover-class="hover-active" @click="showLoginModal = true">立即登录</view>
  18. </view>
  19. <view class="login-card-right">
  20. <image :src="getFileUrl('img/icon/welcom.png')" mode="widthFix" class="welcome-img"></image>
  21. </view>
  22. </view>
  23. <view class="banner-box">
  24. <image :src="getFileUrl('img/icon/zptj.png')" mode="widthFix" class="banner-img"></image>
  25. </view>
  26. <!-- 列表 -->
  27. <view class="list-box">
  28. <view class="food-card" v-for="(item, index) in foodList" :key="index">
  29. <!-- 菜品图片 -->
  30. <image :src="getFileUrl(item.image)" mode="aspectFill" class="food-image"></image>
  31. <!-- 菜品信息 -->
  32. <view class="food-info">
  33. <!-- 标题和月售 -->
  34. <view class="food-header">
  35. <view class="food-left">
  36. <view class="food-name">{{ item.name }}</view>
  37. <view class="food-sales">
  38. <image :src="getFileUrl('img/icon/star.png')" mode="aspectFill" class="star-icon"></image>
  39. <text class="sales-text">月售:{{ item.sales }}</text>
  40. </view>
  41. </view>
  42. <view class="food-right">
  43. <view class="food-price">
  44. <text class="price-symbol">¥</text>
  45. <text class="price-main">{{ getPriceMain(item.price) }}</text>
  46. <text class="price-decimal">.{{ getPriceDecimal(item.price) }}</text>
  47. </view>
  48. </view>
  49. </view>
  50. <!-- 标签 -->
  51. <view class="food-tags">
  52. <view v-for="(tag, tagIndex) in item.tags" :key="tagIndex" class="food-tag" :class="tag.type">
  53. {{ tag.text }}
  54. </view>
  55. </view>
  56. <!-- 描述 -->
  57. <view class="food-desc">{{ item.description }}</view>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 登录弹窗组件 -->
  63. <view class="login-modal-wrapper">
  64. <LoginModal v-model:open="showLoginModal" @success="handleLoginSuccess" @cancel="handleLoginCancel" />
  65. </view>
  66. <!-- 底部导航 -->
  67. <TabBar />
  68. </view>
  69. </template>
  70. <script setup>
  71. import { ref } from "vue";
  72. import { onLoad } from "@dcloudio/uni-app";
  73. import TabBar from "@/components/TabBar.vue";
  74. import LoginModal from "@/pages/components/LoginModal.vue";
  75. import { go } from "@/utils/utils.js";
  76. import { getFileUrl } from '@/utils/file.js';
  77. import { useUserStore } from '@/store/user.js';
  78. const userStore = useUserStore();
  79. const showLoginModal = ref(false);
  80. // 示例菜品数据
  81. const foodList = ref([
  82. {
  83. image: '/static/demo.png',
  84. name: '川派辣卤牛杂川派辣卤牛杂煲川派辣卤牛杂煲川派辣卤牛杂煲煲',
  85. sales: 160,
  86. tags: [
  87. { text: '招牌', type: 'signature' },
  88. { text: '中辣', type: 'spicy' }
  89. ],
  90. description: '香煎 M9 和牛粒是将澳洲顶级 M9 和牛切成均匀小粒,以高温快煎方式锁住肉汁。',
  91. price: '49.8'
  92. },
  93. {
  94. image: '/static/demo.png',
  95. name: '川派辣卤牛杂煲',
  96. sales: 160,
  97. tags: [
  98. { text: '招牌', type: 'signature' },
  99. { text: '中辣', type: 'spicy' }
  100. ],
  101. description: '香煎 M9 和牛粒是将澳洲顶级 M9 和牛切成均匀小粒,以高温快煎方式锁住肉汁。',
  102. price: '49.8'
  103. }
  104. ]);
  105. // 获取价格整数部分
  106. const getPriceMain = (price) => {
  107. if (!price) return '';
  108. const priceStr = String(price);
  109. const dotIndex = priceStr.indexOf('.');
  110. return dotIndex > -1 ? priceStr.substring(0, dotIndex) : priceStr;
  111. };
  112. // 获取价格小数部分
  113. const getPriceDecimal = (price) => {
  114. if (!price) return '';
  115. const priceStr = String(price);
  116. const dotIndex = priceStr.indexOf('.');
  117. return dotIndex > -1 ? priceStr.substring(dotIndex + 1) : '';
  118. };
  119. // 登录成功回调
  120. const handleLoginSuccess = (res) => {
  121. console.log('登录成功:', res);
  122. };
  123. // 取消登录回调
  124. const handleLoginCancel = () => {
  125. console.log('用户取消登录');
  126. };
  127. onLoad((e) => { });
  128. </script>
  129. <style scoped lang="scss">
  130. .content {
  131. .top-img {
  132. width: 100%;
  133. height: 572rpx;
  134. }
  135. .content-box {
  136. width: 100%;
  137. box-sizing: border-box;
  138. padding: 0 30rpx 140rpx;
  139. .shop-info {
  140. display: flex;
  141. align-items: center;
  142. justify-content: center;
  143. width: 100%;
  144. height: 100rpx;
  145. background-color: #fff;
  146. border-radius: 17rpx;
  147. margin-top: -50rpx;
  148. position: relative;
  149. z-index: 2;
  150. box-shadow: 0rpx 0rpx 11rpx 0rpx rgba(0, 0, 0, 0.06);
  151. .shop-img {
  152. width: 45rpx;
  153. height: 38rpx;
  154. margin-right: 20rpx;
  155. }
  156. .shop-name {
  157. font-weight: bold;
  158. font-size: 31rpx;
  159. color: #151515;
  160. }
  161. }
  162. }
  163. .login-card {
  164. width: 100%;
  165. min-height: 240rpx;
  166. background-color: #fff;
  167. border-radius: 17rpx;
  168. margin-top: 20rpx;
  169. box-sizing: border-box;
  170. padding: 30rpx;
  171. display: flex;
  172. align-items: center;
  173. justify-content: space-between;
  174. box-shadow: 0rpx 0rpx 11rpx 0rpx rgba(0, 0, 0, 0.06);
  175. .login-card-left {
  176. flex: 1;
  177. display: flex;
  178. flex-direction: column;
  179. justify-content: center;
  180. padding-right: 20rpx;
  181. .welcome-title {
  182. font-size: 36rpx;
  183. font-weight: bold;
  184. color: #151515;
  185. margin-bottom: 16rpx;
  186. line-height: 1.4;
  187. }
  188. .welcome-desc {
  189. font-size: 27rpx;
  190. color: #666666;
  191. margin-bottom: 24rpx;
  192. line-height: 1.4;
  193. }
  194. .login-btn {
  195. width: 160rpx;
  196. height: 53rpx;
  197. background: #2E2E2E;
  198. display: flex;
  199. align-items: center;
  200. justify-content: center;
  201. font-size: 27rpx;
  202. color: #FFFFFF;
  203. font-weight: 500;
  204. cursor: pointer;
  205. transition: opacity 0.3s;
  206. &:active {
  207. opacity: 0.8;
  208. }
  209. }
  210. }
  211. .login-card-right {
  212. flex-shrink: 0;
  213. display: flex;
  214. align-items: center;
  215. justify-content: center;
  216. .welcome-img {
  217. width: 200rpx;
  218. height: auto;
  219. }
  220. }
  221. }
  222. // 登录弹窗层级设置
  223. .login-modal-wrapper {
  224. position: relative;
  225. z-index: 100;
  226. :deep(.uni-popup) {
  227. z-index: 100 !important;
  228. }
  229. }
  230. .banner-box {
  231. width: 100%;
  232. height: 100%;
  233. display: flex;
  234. align-items: center;
  235. justify-content: center;
  236. margin-top: 40rpx;
  237. .banner-img {
  238. width: 480rpx;
  239. height: 66rpx;
  240. margin: 0 auto;
  241. }
  242. }
  243. .list-box {
  244. width: 100%;
  245. margin-top: 40rpx;
  246. padding-bottom: 40rpx;
  247. .food-card {
  248. width: 100%;
  249. background-color: #fff;
  250. border-radius: 17rpx;
  251. overflow: hidden;
  252. margin-bottom: 30rpx;
  253. box-shadow: 0rpx 0rpx 11rpx 0rpx rgba(0, 0, 0, 0.06);
  254. .food-image {
  255. width: 100%;
  256. height: 400rpx;
  257. display: block;
  258. }
  259. .food-info {
  260. padding: 30rpx;
  261. position: relative;
  262. box-sizing: border-box;
  263. .food-header {
  264. display: flex;
  265. align-items: center;
  266. justify-content: space-between;
  267. margin-bottom: 20rpx;
  268. .food-name {
  269. font-size: 32rpx;
  270. font-weight: bold;
  271. color: #151515;
  272. flex: 1;
  273. max-width: 360rpx;
  274. overflow: hidden;
  275. text-overflow: ellipsis;
  276. white-space: nowrap;
  277. }
  278. .food-left {
  279. display: flex;
  280. align-items: center;
  281. gap: 20rpx;
  282. }
  283. .food-right {
  284. display: flex;
  285. align-items: center;
  286. gap: 20rpx;
  287. flex-shrink: 0;
  288. }
  289. .food-sales {
  290. display: flex;
  291. align-items: center;
  292. font-size: 24rpx;
  293. color: #999999;
  294. .star-icon {
  295. width: 20rpx;
  296. height: 20rpx;
  297. margin-right: 8rpx;
  298. }
  299. .sales-text {
  300. font-size: 24rpx;
  301. color: #999999;
  302. }
  303. }
  304. .food-price {
  305. display: flex;
  306. align-items: baseline;
  307. color: #FF3B30;
  308. line-height: 1;
  309. .price-symbol {
  310. font-size: 24rpx;
  311. font-weight: bold;
  312. }
  313. .price-main {
  314. font-size: 44rpx;
  315. font-weight: bold;
  316. }
  317. .price-decimal {
  318. font-size: 24rpx;
  319. font-weight: bold;
  320. }
  321. }
  322. }
  323. .food-tags {
  324. display: flex;
  325. align-items: center;
  326. gap: 12rpx;
  327. margin-bottom: 20rpx;
  328. .food-tag {
  329. padding: 6rpx 16rpx;
  330. border-radius: 6rpx;
  331. font-size: 22rpx;
  332. color: #FFFFFF;
  333. line-height: 1.2;
  334. &.signature {
  335. background: linear-gradient(90deg, #FCB13F 0%, #FC793D 100%);
  336. }
  337. &.spicy {
  338. background: #2E2E2E;
  339. }
  340. }
  341. }
  342. .food-desc {
  343. font-size: 26rpx;
  344. color: #151515;
  345. line-height: 1.6;
  346. margin-top: 20rpx;
  347. }
  348. }
  349. }
  350. }
  351. }
  352. </style>