【UniApp開發小程序】小程序首頁(展示商品、商品搜索、商品分類搜索)【后端基于若依管理系統開發】

文章目錄

  • 界面效果
  • 界面實現
    • 工具js
    • 頁面
      • 首頁
        • 讓文字只顯示兩行
        • 路由跳轉傳遞對象
        • 將商品分為兩列顯示
        • 使用中劃線劃掉原價
  • 后端
    • 商品
      • controller
      • service
      • mapper
      • sql

界面效果

【說明】

  • 界面中商品的圖片來源于閑魚,若侵權請聯系刪除
  • 關于商品分類頁面的實現,請在我的Uniapp系列文章中尋找來查看
  • 關于頁面中懸浮按鈕的實現,請在我的Uniapp系列文章中尋找來查看

在這里插入圖片描述

在這里插入圖片描述

界面實現

工具js

該工具類的作用是,給定一個圖片的url地址,計算出圖片的高寬比,計算高寬比的作用是讓圖片可以按照正常比例顯示

/*** 獲取uuid*/
export default {/*** 獲取高寬比 乘以 100%*/getAspectRatio(url) {uni.getImageInfo({src: url,success: function(res) {let aspectRatio = res.height * 100.0 / res.width;// console.log("aspectRatio:" + aspectRatio);return aspectRatio + "%";}});},
}

頁面

首頁

<template><view class="content"><view style="display: flex;align-items: center;"><u-search placeholder="請輸入商品名稱" v-model="searchForm.keyword" @search="listProductVo" :showAction="false":clearabled="true"></u-search><text class="iconfont" style="font-size: 35px;" @click="selectCategory()">&#xe622;</text></view><u-row customStyle="margin-top: 10px" gutter="10" align="start" v-if="productList[0].length>0&&loadData==false"><u-col span="6" class="col" v-for="(data,index) in productList" :key="index"><view class="productVoItem" v-for="(productVo,index1) in data" :key="index1"@click="seeProductDetail(productVo)"><u--image v-if="productVo.picList!=null&&productVo.picList.length>0" :showLoading="true":src="productVo.picList[0]" width="100%" :height="getAspectRatio(productVo.picList[0])"radius="10" mode="widthFix"></u--image><!-- <u--image v-else :showLoading="true" :src="src" @click="click"></u--image> --><view class="productMes"><text class="productName">【{{productVo.name}}】</text><text>{{productVo.description==null?'':productVo.description}}</text></view><view style="display: flex;align-items: center;"><!-- 現價 --><view class="price"><text class="number">{{productVo.price}}</text>/{{productVo.unit}}</view><view style="width: 10px;"></view><!-- 原價 --><view class="originPrice">¥{{productVo.originalPrice}}/{{productVo.unit}}</view></view><view style="display: flex;align-items: center;"><u--image :src="productVo.avatar" width="20" height="20" shape="circle"></u--image><view style="width: 10px;"></view><view> {{productVo.nickname}}</view></view></view></u-col></u-row><u-empty v-if="productList[0].length==0&&loadData==false" mode="data" texColor="#ffffff" iconSize="180"iconColor="#D7DEEB" text="所選擇的分類沒有對應的商品,請重新選擇" textColor="#D7DEEB" textSize="18" marginTop="30"></u-empty><view style="margin-top: 20px;" v-if="loadData==true"><u-skeleton :loading="true" :animate="true" rows="10"></u-skeleton></view><!-- 浮動按鈕 --><FloatButton @click="cellMyProduct()"><u--image :src="floatButtonPic" shape="circle" width="60px" height="60px"></u--image></FloatButton></view>
</template><script>import FloatButton from "@/components/FloatButton/FloatButton.vue";import {listProductVo} from "@/api/market/prodct.js";import pictureApi from "@/utils/picture.js";export default {components: {FloatButton},onShow: function() {let categoryNameList = uni.getStorageSync("categoryNameList");if (categoryNameList) {this.categoryNameList = categoryNameList;this.searchForm.productCategoryId = uni.getStorageSync("productCategoryId");this.searchForm.keyword = this.getCategoryLayerName(this.categoryNameList);uni.removeStorageSync("categoryNameList");uni.removeStorageSync("productCategoryId");this.listProductVo();}},data() {return {title: 'Hello',// 浮動按鈕的圖片floatButtonPic: require("@/static/cellLeaveUnused.png"),searchForm: {// 商品搜索關鍵詞keyword: "",productCategoryId: undefined},productList: [[],[]],loadData: false,}},onLoad() {},created() {this.listProductVo();},methods: {/*** 查詢商品vo集合*/listProductVo() {this.loadData = true;listProductVo(this.searchForm).then(res => {this.loadData = false;// console.log("listProductVo:" + JSON.stringify(res))let productVoList = res.rows;this.productList = [[],[]];for (var i = 0; i < productVoList.length; i++) {if (i % 2 == 0) {// 第一列數據this.productList[0].push(productVoList[i]);} else {// 第二列數據this.productList[1].push(productVoList[i]);}}})},/*** 跳轉到賣閑置頁面*/cellMyProduct() {console.log("我要賣閑置");uni.navigateTo({url: "/pages/sellMyProduct/sellMyProduct"})},/*** 獲取高寬比 乘以 100%*/getAspectRatio(url) {return pictureApi.getAspectRatio(url);},/*** 選擇分類*/selectCategory() {uni.navigateTo({url: "/pages/sellMyProduct/selectCategory"})},/*** 獲取商品名稱*/getCategoryLayerName() {let str = '';for (let i = 0; i < this.categoryNameList.length - 1; i++) {str += this.categoryNameList[i] + '/';}return str + this.categoryNameList[this.categoryNameList.length - 1];},/*** 查看商品的詳情*/seeProductDetail(productVo) {// console.log("productVo:"+JSON.stringify(productVo))uni.navigateTo({url: "/pages/product/detail?productVo=" + encodeURIComponent(JSON.stringify(productVo))})}}}
</script><style lang="scss">.content {padding: 20rpx;.col {width: 50%;}.productVoItem {margin-bottom: 20px;.productMes {overflow: hidden;text-overflow: ellipsis;display: -webkit-box;/* 顯示2行 */-webkit-line-clamp: 2;-webkit-box-orient: vertical;.productName {font-weight: bold;}}.price {color: #ff0000;font-weight: bold;.number {font-size: 22px;}}.originPrice {color: #A2A2A2;font-size: 15px;// 給文字添加中劃線text-decoration: line-through;}}}
</style>

讓文字只顯示兩行

overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
/* 顯示2行 */
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;

在這里插入圖片描述

路由跳轉傳遞對象

因為首頁已經查詢到商品的很多信息了,點擊查看商品詳情的時候,很多信息不需要再查詢一遍了,可以直接將商品的已知信息通過路由傳遞到新的頁面去,需要注意的時候,將對象作為參數傳遞之前,需要先將對象進行編碼

uni.navigateTo({url: "/pages/product/detail?productVo=" + encodeURIComponent(JSON.stringify(productVo))
})

將商品分為兩列顯示

首先將查詢到的商品分為兩組

let productVoList = res.rows;
this.productList = [[],[]
];
for (var i = 0; i < productVoList.length; i++) {if (i % 2 == 0) {// 第一列數據this.productList[0].push(productVoList[i]);} else {// 第二列數據this.productList[1].push(productVoList[i]);}
}

然后在布局中使用行列布局即可,即使用一行兩列的方式來顯示商品信息
在這里插入圖片描述

使用中劃線劃掉原價

在這里插入圖片描述

// 給文字添加中劃線
text-decoration: line-through;

后端

商品

controller

 /*** 查詢商品Vo列表*/@PreAuthorize("@ss.hasPermi('market:product:list')")@PostMapping("/listProductVo")@ApiOperation("獲取商品列表")public TableDataInfo listProductVo(@RequestBody ProductVo productVo) {startPage();if (productVo.getProductCategoryId() != null) {// --if-- 當分類不為空的時候,只按照分類來搜索productVo.setKeyword(null);}List<ProductVo> list = productService.selectProductVoList(productVo);return getDataTable(list);}

service

/*** 查詢商品Vo列表** @param productVo* @return*/
@Override
public List<ProductVo> selectProductVoList(ProductVo productVo) {
//        List<ProductVo> productVoList = new ArrayList<>();List<ProductVo> productVoList = baseMapper.selectProductVoList(productVo);///設置每個商品的圖片// 獲取所有商品的idList<Long> productIdList = productVoList.stream().map(item -> {return item.getId();}).collect(Collectors.toList());// 查詢出所有商品的圖片if (productIdList.size() > 0) {List<Picture> pictureList = pictureService.selectPictureListByItemIdListAndType(productIdList, PictureType.PRODUCT.getType());Map<Long, List<String>> itemIdAndPicList = new HashMap<>();for (Picture picture : pictureList) {if (!itemIdAndPicList.containsKey(picture.getItemId())) {List<String> picList = new ArrayList<>();picList.add(picture.getAddress());itemIdAndPicList.put(picture.getItemId(), picList);} else {itemIdAndPicList.get(picture.getItemId()).add(picture.getAddress());}}// 給每個商品設置圖片for (ProductVo vo : productVoList) {vo.setPicList(itemIdAndPicList.get(vo.getId()));}}return productVoList;
}

mapper

void starNumDiffOne(@Param("productId") Long productId);

sql

  <select id="selectProductVoList" parameterType="ProductVo" resultMap="ProductVoResult">SELECTp.id,p.NAME,p.description,p.original_price,p.price,p.product_category_id,pc.NAME AS productCategoryName,p.user_id,u.user_name as username,u.nick_name as nickname,u.avatar as avatar,p.reviewer_id,u1.user_name as reviewerUserName,p.fineness,p.unit,p.STATUS,p.is_contribute,p.functional_status,p.brand_id,b.NAME AS brandNameFROMproduct AS pLEFT JOIN product_category AS pc ON p.product_category_id = pc.idLEFT JOIN brand AS b ON p.brand_id = b.idLEFT JOIN sys_user AS u ON p.user_id = u.user_idLEFT JOIN sys_user AS u1 ON p.reviewer_id = u1.user_id<where><if test="keyword != null  and keyword != ''">and p.name like concat('%', #{keyword}, '%')</if><if test="keyword != null  and keyword != ''">or p.description like concat('%', #{keyword}, '%')</if><if test="productCategoryId != null  and productCategoryId != ''">and p.product_category_id =#{productCategoryId}</if></where></select>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/38086.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/38086.shtml
英文地址,請注明出處:http://en.pswp.cn/news/38086.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

MySQL基礎篇

一、MySQL基礎 黑窗口命令操作: 連接MySQL服務器&#xff1a;mysql -u用戶名 -p密碼 [-h數據庫服務器的IP地址 -P端口號] ? -h 參數不加&#xff0c;默認連接的是本地 127.0.0.1 的MySQL服務器 -P 參數不加&#xff0c;默認連接的端口號是 3306 、 **上述指令&#xff0c;可…

建庫、建表、修改表、復制表、字符類型、數值類型、枚舉類型、日期時間類型、檢索目錄、數據導入命令、數據導入步驟、數據導出命令、非空、默認值、唯一索

Top NSD DBA DAY04 案例1&#xff1a;表管理案例2&#xff1a;數據類型案例3&#xff1a;數據批量處理案例4&#xff1a;表頭基本約束 1 案例1&#xff1a;表管理 1.1 問題 建庫練習建表練習修改表練習 1.2 方案 在MySQL50主機完成練習。 1.3 步驟 實現此案例需要按照如…

升級版“斯坦福AI小鎮”來了,這次的AI Agents有點不一樣

文娛是大模型落地的一個重要方向。 數科星球原創 作者丨苑晶 編輯丨大兔 八月中旬&#xff0c;AIGC游戲的風潮撲面而來。在游戲大廠按捺不住投入巨資的背景下&#xff0c;數科星球&#xff08;ID&#xff1a;digital-planet&#xff09;接觸到了多名業內精英也投身于此。人工…

Kafka第一課概述與安裝

生產經驗 面試重點 Broker面試重點 代碼,開發重點 67 章了解 如何記錄行為數據 1. Kafka概述 1.產生原因 前端 傳到日志 日志傳到Flume 傳到HADOOP 但是如果數據特比大&#xff0c;HADOOP就承受不住了 2.Kafka解決問題 控流消峰 Flume傳給Kafka 存到Kafka Hadoop 從Kafka…

Qt掃盲-Qt Paint System 概述

Qt Paint System 概述 一、概述二、繪圖設備和后端1. Widget2. Image3. Pixmap4. OpenGL繪制設備5. Picture6. 自定義繪制后端 三、繪圖與填充1. Drawing2. 填充 Filling 四、坐標系統1. 渲染Window-Viewport轉換 五、讀寫圖像文件1. QMovie 六、繪圖相關設備 一、概述 Qt的pa…

【數據庫】P2 SELECT 與 SQL注釋

SELECT 檢索單個列檢索多個列檢索所有列不重復的結果 DISTINCT限制結果 LIMIT 與 OFFSET注釋行內注釋多行注釋 檢索單個列 從 Products 表中檢索一個名為 prod_name 的列&#xff1b; SELECT prod_name FROM Products;【1】返回的數據可能是無序的&#xff0c;除非規定了順序…

7.5.tensorRT高級(2)-RAII接口模式下的生產者消費者多batch實現

目錄 前言1. RAII接口模式封裝生產者消費者2. 問答環節總結 前言 杜老師推出的 tensorRT從零起步高性能部署 課程&#xff0c;之前有看過一遍&#xff0c;但是沒有做筆記&#xff0c;很多東西也忘了。這次重新擼一遍&#xff0c;順便記記筆記。 本次課程學習 tensorRT 高級-RAI…

原生JS手寫掃雷小游戲

場景 實現一個完整的掃雷游戲需要一些復雜的邏輯和界面交互。我將為你提供一個簡化版的掃雷游戲示例&#xff0c;幫助你入門。請注意&#xff0c;這只是一個基本示例&#xff0c;你可以根據自己的需求進行擴展和改進。 思路 創建游戲板&#xff08;Grid&#xff09;&#xff1…

軟考:中級軟件設計師:文件管理,索引文件結構,樹型文件結構,位示圖,數據傳輸方式,微內核

軟考&#xff1a;中級軟件設計師: 提示&#xff1a;系列被面試官問的問題&#xff0c;我自己當時不會&#xff0c;所以下來自己復盤一下&#xff0c;認真學習和總結&#xff0c;以應對未來更多的可能性 關于互聯網大廠的筆試面試&#xff0c;都是需要細心準備的 &#xff08;1…

小森動畫回憶錄(二)-瀏覽哆啦a夢的四次元口袋

// DoraemonProps結構用于存儲單個道具信息 struct DoraemonProps{// 道具名稱string name;// 道具用途string UseOfProps; };// 從文件加載哆啦A夢道具信息到vector void LoadDoraemonProps(vector<DoraemonProps>& DoraemonProps) {// 創建文件輸入流ifstream str…

人臉識別技術應用安全管理規定(試行)

近年來&#xff0c;人臉識別技術不斷成熟&#xff0c;已大量應用于治安管理、金融支付、門禁考勤等諸多領域&#xff0c;極大便捷了公眾生活。然而&#xff0c;人臉識別技術在得到廣泛應用的同時&#xff0c;仍存在一些不規范現象。人臉識別因其技術特點&#xff0c;涉及公眾敏…

node.js 基礎高并發案例

什么是高并發 高并發是指系統在同一時間段內需要處理大量的并發請求或同時進行大量的操作。在計算機領域中&#xff0c;高并發通常指的是在短時間內有大量的用戶或客戶端同時訪問系統或進行操作&#xff0c;對系統的并發處理能力提出了較高的要求。 高并發的特點包括 大量的…

Python學習筆記第五十五天(Pandas CSV文件)

Python學習筆記第五十五天 Pandas CSV 文件read_csv()to_string()to_csv() 數據處理head()tail()fillna() info() 后記 Pandas CSV 文件 CSV&#xff08;Comma-Separated Values&#xff0c;逗號分隔值&#xff0c;有時也稱為字符分隔值&#xff0c;因為分隔字符也可以不是逗號…

【嵌入式學習筆記】嵌入式入門7——IIC總線協議

1.IIC簡介 IIC即Inter Integrated Circuit&#xff0c;集成電路總線&#xff0c;是一種同步&#xff0c;串行&#xff0c;半雙工通信總線。 IIC總線協議——總線就是傳輸數據通道&#xff0c;協議就是傳輸數據的規則&#xff0c;有以下特點&#xff1a; 由時鐘線SCL和數據線S…

ES踩坑記錄之集群間通信異常造成節點無法加入

問題描述 公司新搭了一套ES集群&#xff0c;4臺機器&#xff0c;ES版本7.5.0&#xff0c;前期搭建十分順利&#xff0c;但集群運行一段時間后會出現問題。問題具體體現為節點間通訊異常&#xff0c;集群會重新選主&#xff0c;但選主之后只能通過新的主節點進行集群操作&#…

【Linux】可重入函數 volatile關鍵字 以及SIGCHLD信號

可重入函數 volatile關鍵字 以及SIGCHLD信號 一、可重入函數1、引入2、可重入函數的判斷 二、volatile關鍵字1、引入2、關于編譯器的優化的簡單討論 三、SIGCHLD信號 一、可重入函數 1、引入 我們來先看一個例子來幫助我們理解什么是可重入函數&#xff1a; 假設我們現在要對…

EthGlobal 巴黎站 Chainlink 獲獎項目介紹

在 Web3 中&#xff0c;每一周都至關重要。項目的發布、版本的發布以及協議的更新以驚人的速度推出。開發者必須保持學習&#xff0c;隨時了解最新的工具&#xff0c;并將所有他們所學的東西&#xff08;無論是舊的還是新的&#xff09;聯系起來&#xff0c;以構建推動 Web3 技…

PLUS操作流程、應用與實踐,多源不同分辨率數據的處理、ArcGIS的應用、PLUS模型的應用、InVEST模型的應用

PLUS模型是由中國地質大學&#xff08;武漢&#xff09;地理與信息工程學院高性能空間計算智能實驗室開發&#xff0c;是一個基于柵格數據的可用于斑塊尺度土地利用/土地覆蓋(LULC)變化模擬的元胞自動機(CA)模型。PLUS模型集成了基于土地擴張分析的規則挖掘方法和基于多類型隨機…

Word轉PDF在線轉換如何操作?分享轉換技巧

現如今&#xff0c;pdf轉換器已成為大家日常辦公學習必不可少的工具&#xff0c;市場上的pdf轉換器主要有兩種類型&#xff0c;一種是需要下載安裝的&#xff0c;另一種是網頁版&#xff0c;打開就可以使用的&#xff0c;今天小編給大家推薦一個非常好用的網頁版pdf轉換器&…

基于jvm-sandbox的imock開發指南

基于jvm-sandbox的imock開發指南 團隊今年的指標是為公司提供一個方法級的mock平臺&#xff0c; 這個重要的任務落在了我的身上。 0、明確團隊的需求 支持java后端服務方法級別的mock&#xff0c;對沒有測試環境的第三方服務進行mock&#xff0c;增加團隊覆蓋率。 啟用&#x…