3 Commity 1e45b042d6 ... 2233b0b16f

Autor SHA1 Wiadomość Data
  zrug 2233b0b16f api HomepageApiController 10 miesięcy temu
  zrug 5815e01dba index page fix 10 miesięcy temu
  zrug bfbad42de5 mp project config 10 miesięcy temu

+ 6 - 0
08.src/Xingxi-mp/config.js

@@ -0,0 +1,6 @@
+export const baseUrl = "https://接口地址"; // 服务器地址
+// export const baseUrl = "http://测试接口地址"; // 测试服务器地址
+
+// export const ossHost = "https://res.zrug.top";
+export const version = "0.0.1"; // 版本号
+export const version_desc = "接口基础";

+ 15 - 14
08.src/Xingxi-mp/pages/index/index.wxml

@@ -47,21 +47,22 @@
     </view>
   </view>
   <view class="goods">
-    <view wx:for="{{goodsList}}" wx:key="index" class="goods-item">
-      <view class="goods-image">
-        <!-- <image src="{{item.imageUrl}}" class="goods-image"></image> -->
-      </view>
-      <view class="goods-info">
-        <text class="goods-name">{{item.name}}</text>
-        <text class="goods-price">{{item.price}}</text>
-      </view>
-      <view class="goods-action">
-        <view class="favorite">
-          <!-- <image src="{{item.favoriteIcon}}" class="favorite-icon"></image> -->
-          fav
+    <view class="goods-row" wx:for="{{goodsList}}" wx:key="index" wx:for-item="row">
+      <view class="goods-item" wx:for="{{row}}" wx:key="itemIndex">
+        <view class="goods-image">
+          <image src="{{item.imageUrl}}" class="goods-image-inner"></image>
+        </view>
+        <view class="goods-info">
+          <text class="goods-name">{{item.name}}</text>
+          <text class="goods-price">¥{{item.price}}</text>
+        </view>
+        <view class="goods-action">
+          <view class="favorite">
+            <image src="/images/index/fav.png" class="favorite-icon"></image>
+          </view>
+          <button class="add-to-cart">加入购物车</button>
+          <button class="buy-now">立即购买</button>
         </view>
-        <button class="add-to-cart">Add to Cart</button>
-        <button class="buy-now">Buy Now</button>
       </view>
     </view>
   </view>

+ 91 - 2
08.src/Xingxi-mp/pages/index/index.wxss

@@ -127,6 +127,95 @@ page {
   height: 100%;
 }
 .goods {
-  min-height: 800rpx;
-  
+  display: flex;
+  flex-direction: column;
+  padding: 21rpx 21rpx 0 21rpx;
+}
+
+.goods-row {
+  display: flex;
+  flex-direction: row;
+  justify-content: space-evenly;
+  margin-bottom: 21rpx;
+}
+
+.goods-item {
+  width: 326rpx; /* 313*1.0417 */
+  background: #fff;
+  border-radius: 21rpx; /* 20*1.0417 */
+  box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.05);
+  overflow: hidden;
+  display: flex;
+  flex-direction: column;
+}
+
+.goods-image {
+  width: 326rpx;
+  height: 326rpx;
+  margin: 0;
+  border-top-left-radius: 21rpx;
+  border-top-right-radius: 21rpx;
+  border-bottom-left-radius: 0;
+  border-bottom-right-radius: 0;
+  overflow: hidden;
+  background: #f7f7f7;
+}
+.goods-image-inner {
+  width: 100%;
+  height: 100%;
+  object-fit: cover;
+}
+.goods-info {
+  padding: 16rpx 21rpx 0 21rpx;
+}
+.goods-name {
+  font-size: 18rpx;
+  color: #333;
+  display: block;
+  margin-bottom: 8rpx;
+  font-weight: bold;
+}
+.goods-price {
+  font-size: 20rpx;
+  color: #e4393c;
+  font-weight: bold;
+}
+.goods-action {
+  display: flex;
+  align-items: center;
+  justify-content: flex-end;
+  padding: 16rpx 21rpx 21rpx 21rpx;
+}
+.favorite {
+  width: 32rpx;
+  height: 32rpx;
+}
+.favorite-icon {
+  width: 100%;
+  height: 100%;
+}
+.add-to-cart,
+.buy-now {
+  width: 105rpx;
+  height: 36rpx;
+  line-height: 36rpx;
+  font-size: 16rpx;
+  border-radius: 6rpx;
+  margin-left: 8rpx;
+  padding: 0;
+  border: none;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  box-sizing: border-box;
+}
+.add-to-cart {
+  background: #fff;
+  color: #7AC7B5;
+  border: 2rpx solid #7AC7B5;
+}
+.buy-now {
+  background: #7AC7B5;
+  color: #fff;
+  border: none;
 }

+ 3 - 2
08.src/Xingxi-mp/project.private.config.json

@@ -1,7 +1,8 @@
 {
   "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
-  "projectname": "wx-mp-1",
+  "projectname": "Xingxi-mp",
   "setting": {
     "compileHotReLoad": true
-  }
+  },
+  "libVersion": "3.8.0"
 }

+ 222 - 0
08.src/Xingxi-mp/service/api.js

@@ -0,0 +1,222 @@
+import http from "../utils/http";
+
+// 服务器存活检测接口,返回200表示存活,否则表示不存活
+export const Ping = {
+  get: function () {
+    return http.get("/api/alive/ping");
+  },
+  post: function (data) {
+    return http.post("/api/alive/ping", data);
+  },
+}
+
+// 小程序体量限制1M,图片必须放在外部cdn上
+// 七牛云存储,获取token
+export const Qiniu = {
+  token: function () {
+    // TODO: get token from app first, if expired, request new
+    return http.post("/qiniu/token");
+  },
+}
+
+// HomepageApiController
+export const HomepageApi = {
+  /** 
+   * 返回示例:{
+    "bannerList": [
+      {
+        "createUser": "",
+        "createTime": "",
+        "updateUser": "",
+        "updateTime": "",
+        "remark": "",
+        "params": {
+          "": {}
+        },
+        "bannerId": 0,
+        "bannerUrl": "",
+        "bannerType": "",
+        "prodId": 0,
+        "newsId": 0,
+        "sort": 0,
+        "delFlag": ""
+      }
+    ]
+  }
+  */
+  getBanners: function (payload) {
+    return http.post("/api/store/homepage/banners", {
+      ...payload,
+    });
+  },
+
+  /**
+   * 返回示例:{
+    "ipInfoList": [
+      {
+        "createUser": "",
+        "createTime": "",
+        "updateUser": "",
+        "updateTime": "",
+        "remark": "",
+        "params": {
+          "": {}
+        },
+        "ipId": 0,
+        "ipName": "",
+        "ipUrl": "",
+        "colorNo": "",
+        "sort": 0,
+        "delFlag": ""
+      }
+    ]
+  }
+  */
+  getIpInfos: function (payload) {
+    return http.post("/api/store/homepage/ipInfos", {
+      ...payload,
+    });
+  },
+
+  /**
+   * 返回示例:{
+    "titleList": [
+      ""
+    ]
+  }
+  */
+  getTitles: function (payload) {
+    return http.post("/api/store/homepage/titles", {
+      ...payload,
+    });
+  },
+
+  /**
+   * 返回示例:{
+    "prodList": [
+      {
+        "id": 0,
+        "prodId": 0,
+        "sort": 0,
+        "prodPicList": [
+          {
+            "createUser": "",
+            "createTime": "",
+            "updateUser": "",
+            "updateTime": "",
+            "remark": "",
+            "params": {
+              "": {}
+            },
+            "id": 0,
+            "prodId": 0,
+            "picUrl": "",
+            "sort": 0,
+            "delFlag": ""
+          }
+        ]
+      }
+    ]
+  }
+  */
+  getLeftProds: function (payload) {
+    return http.post("/api/store/homepage/leftProds", {
+      ...payload,
+    });
+  },
+
+  /**
+   * 返回示例:{
+    "prodList": [
+      {
+        "id": 0,
+        "prodId": 0,
+        "sort": 0,
+        "prodPicList": [
+          {
+            "createUser": "",
+            "createTime": "",
+            "updateUser": "",
+            "updateTime": "",
+            "remark": "",
+            "params": {
+              "": {}
+            },
+            "id": 0,
+            "prodId": 0,
+            "picUrl": "",
+            "sort": 0,
+            "delFlag": ""
+          }
+        ]
+      }
+    ]
+  }
+  */
+  getMiddleProds: function (payload) {
+    return http.post("/api/store/homepage/middleProds", {
+      ...payload,
+    });
+  },
+
+  /**
+   * 返回示例:{
+    "prodList": [
+      {
+        "id": 0,
+        "prodId": 0,
+        "sort": 0,
+        "prodPicList": [
+          {
+            "createUser": "",
+            "createTime": "",
+            "updateUser": "",
+            "updateTime": "",
+            "remark": "",
+            "params": {
+              "": {}
+            },
+            "id": 0,
+            "prodId": 0,
+            "picUrl": "",
+            "sort": 0,
+            "delFlag": ""
+          }
+        ]
+      }
+    ]
+  }
+  */
+  getRightProds: function (payload) {
+    return http.post("/api/store/homepage/rightProds", {
+      ...payload,
+    });
+  },
+
+  /**
+   * 返回示例:{
+    "prodClassList": [
+      {
+        "createUser": "",
+        "createTime": "",
+        "updateUser": "",
+        "updateTime": "",
+        "remark": "",
+        "params": {
+          "": {}
+        },
+        "prodClassId": 0,
+        "className": "",
+        "classUrl": "",
+        "sort": 0,
+        "delFlag": ""
+      }
+    ]
+  }
+  */
+  getProdClasses: function (payload) {
+    return http.post("/api/store/homepage/prodClasses", {
+      ...payload,
+    });
+  },
+}

+ 70 - 0
08.src/Xingxi-mp/utils/http.js

@@ -0,0 +1,70 @@
+import { baseUrl } from "../config";
+
+function getHeader() {
+  if (wx.getStorageSync("token")) {
+    return {
+      "content-type": "application/json",
+      "x-token": wx.getStorageSync("token"),
+    };
+  }
+  return {
+    "content-type": "application/json",
+  };
+}
+
+function showErrToast(e) {
+  wx.showToast({
+    title: typeof e === "string" ? e : e.errMsg || e.toString(),
+    icon: "none",
+    duration: 1500,
+  });
+}
+
+function getPromise(url, data, method) {
+  return new Promise((resolve, reject) => {
+    wx.request({
+      url: `${baseUrl}${url}`,
+      header: getHeader(),
+      method: method,
+      data: data,
+      success: function (res) {
+        if (res.data.code === 200) {
+          resolve(res.data.data);
+        } else {
+          if (res.statusCode === 401) {
+            reject(401);
+          } else {
+            reject(res.data.message);
+          }
+        }
+      },
+      fail: function (err) {
+        reject(err);
+      },
+    });
+  }).catch((e) => {
+    if (401 === e) {
+      // redirect to login page
+      wx.navigateTo({
+        url: "/pages/login/login",
+      });
+    } else {
+      console.error(`in promise error, url: ${baseUrl}${url}`);
+      console.error(e);
+      if (e) {
+        showErrToast(e);
+      }
+    }
+  });
+}
+
+const http = {
+  get: function (url, data) {
+    return getPromise(url, data, "GET");
+  },
+  post: function (url, data) {
+    return getPromise(url, data, "POST");
+  },
+};
+
+export default http;