Bladeren bron

fix: 优化小程序代码质量扫描,修复主包体积/未使用JS/资源大小三项问题 - 将 date.ts/uploader.ts 从主包移至对应分包,消除主包未使用JS文件 - 充电页面背景图由 PNG(1197KB) 替换为 SVG(5.4KB) 线条图案 - 压缩 map-bg.jpg (141KB->65KB),删除未使用的 demo 组件

skyline 2 dagen geleden
bovenliggende
commit
600f769727

+ 0 - 7
charge-front/src/components/demo/index.vue

@@ -1,7 +0,0 @@
-<template>
-  <view class="list"> </view>
-</template>
-
-<script setup lang="ts"></script>
-
-<style></style>

+ 1 - 1
charge-front/src/pages-charge/appointment/appointment-backup.vue

@@ -301,7 +301,7 @@ import {onLoad, onShow} from "@dcloudio/uni-app";
 import {ref} from "vue";
 import ChargeMachine from "../machines/charge-machine/charge-machine.vue";
 import PriceDesc from "../machines/price-desc/price-desc.vue";
-import {format} from "@/utils/date";
+import {format} from "../utils/date";
 import {redirect, to} from "../../utils/navigate";
 
 const DAY = 24 * 60 * 60 * 1000;

+ 1 - 1
charge-front/src/pages-charge/appointment/appointment.vue

@@ -323,7 +323,7 @@ import {ref} from "vue";
 import ChargeMachine from "../machines/charge-machine/charge-machine.vue";
 import PriceDesc from "../machines/price-desc/price-desc.vue";
 import StationChargeCoupon from "@/components/station-charge-coupon/station-charge-coupon.vue";
-import {format} from "@/utils/date";
+import {format} from "../utils/date";
 import {redirect, to} from "../../utils/navigate";
 
 

+ 1 - 1
charge-front/src/pages-charge/camera/camera.vue

@@ -85,7 +85,7 @@ import { deCode } from "../../utils/code";
 import { back, redirect } from "../../utils/navigate";
 import { onLoad, onReady } from "@dcloudio/uni-app";
 import { fetchChargeStatus, searchQRCode } from "../../api/charge";
-import { upload } from "@/utils/uploader";
+import { upload } from "../utils/uploader";
 
 const cameraHeight = ref(0);
 const cameraFlash = ref("off");

+ 2 - 2
charge-front/src/pages-charge/ordering/ordering.vue

@@ -2,7 +2,7 @@
   <view class="container">
     <image
       class="bg"
-      src="../static/charge-ordering-bg.png"
+      src="../static/charge-ordering-bg.svg"
       mode="widthFix"
     />
     <view class="body">
@@ -91,7 +91,7 @@
 import { onHide, onLoad, onShow } from "@dcloudio/uni-app";
 import { cancelCharge, fetchChargeStatus, startCharge } from "../../api/charge";
 import { ref } from "vue";
-import { format } from "../../utils/date";
+import { format } from "../utils/date";
 import { to, reLaunch } from "@/utils/navigate";
 
 let timer: any;

BIN
charge-front/src/pages-charge/static/charge-ordering-bg.png


+ 95 - 0
charge-front/src/pages-charge/static/charge-ordering-bg.svg

@@ -0,0 +1,95 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 702 1386" fill="none">
+  <defs>
+    <radialGradient id="glow1" cx="15%" cy="70%" r="50%">
+      <stop offset="0%" stop-color="#2d9e95" stop-opacity="0.05"/>
+      <stop offset="100%" stop-color="#ffffff" stop-opacity="0"/>
+    </radialGradient>
+    <radialGradient id="glow2" cx="85%" cy="20%" r="45%">
+      <stop offset="0%" stop-color="#4a7cff" stop-opacity="0.04"/>
+      <stop offset="100%" stop-color="#ffffff" stop-opacity="0"/>
+    </radialGradient>
+  </defs>
+
+  <!-- White background -->
+  <rect width="702" height="1386" fill="#f8f9fc"/>
+
+  <!-- Subtle ambient glow -->
+  <rect width="702" height="1386" fill="url(#glow1)"/>
+  <rect width="702" height="1386" fill="url(#glow2)"/>
+
+  <!-- === Large faint hexagon - top right (structural) === -->
+  <g transform="translate(620, 200)" stroke="#c5d4ed" stroke-width="0.6" opacity="0.35" fill="none">
+    <polygon points="0,-280 242.5,-140 242.5,140 0,280 -242.5,140 -242.5,-140"/>
+    <polygon points="0,-240 207.8,-120 207.8,120 0,240 -207.8,120 -207.8,-120" opacity="0.45"/>
+    <polygon points="0,-200 173.2,-100 173.2,100 0,200 -173.2,100 -173.2,-100" opacity="0.3"/>
+  </g>
+
+  <!-- === Main hexagon cluster - center-left (anchor) === -->
+  <g transform="translate(130, 750)" stroke="#a8c4dd" fill="none">
+    <polygon points="0,-260 225.2,-130 225.2,130 0,260 -225.2,130 -225.2,-130" stroke-width="0.55" opacity="0.18"/>
+    <polygon points="0,-230 199.2,-115 199.2,115 0,230 -199.2,115 -199.2,-115" stroke-width="0.58" opacity="0.22"/>
+    <polygon points="0,-200 173.2,-100 173.2,100 0,200 -173.2,100 -173.2,-100" stroke-width="0.62" opacity="0.27"/>
+
+    <polygon points="0,-170 147.2,-85 147.2,85 0,170 -147.2,85 -147.2,-85" stroke-width="0.66" opacity="0.32"/>
+    <polygon points="0,-140 121.2,-65 121.2,65 0,140 -121.2,65 -121.2,-65" stroke-width="0.7" opacity="0.38"/>
+    <polygon points="0,-110 95.3,-55 95.3,55 0,110 -95.3,55 -95.3,-55" stroke-width="0.74" opacity="0.44"/>
+
+    <polygon points="0,-80 69.3,-40 69.3,40 0,80 -69.3,40 -69.3,-40" stroke-width="0.78" opacity="0.52"/>
+    <polygon points="0,-52 45,-26 45,26 0,52 -45,26 -45,-26" stroke-width="0.82" opacity="0.62"/>
+    <polygon points="0,-28 24.2,-14 24.2,14 0,28 -24.2,14 -24.2,-14" stroke-width="0.88" opacity="0.75"/>
+  </g>
+
+  <!-- === Small hexagon - bottom left === -->
+  <g transform="translate(90, 1120)" stroke="#b8d0e3" fill="none">
+    <polygon points="0,-130 112.6,-65 112.6,65 0,130 -112.6,65 -112.6,-65" stroke-width="0.58" opacity="0.22"/>
+    <polygon points="0,-100 86.6,-50 86.6,50 0,100 -86.6,50 -86.6,-50" stroke-width="0.64" opacity="0.28"/>
+    <polygon points="0,-72 62.4,-36 62.4,36 0,72 -62.4,36 -62.4,-36" stroke-width="0.7" opacity="0.36"/>
+    <polygon points="0,-46 39.8,-23 39.8,23 0,46 -39.8,23 -39.8,-23" stroke-width="0.76" opacity="0.46"/>
+    <polygon points="0,-24 20.8,-12 20.8,12 0,24 -20.8,12 -20.8,-12" stroke-width="0.84" opacity="0.6"/>
+  </g>
+
+  <!-- === Tiny hexagon - bottom right === -->
+  <g transform="translate(600, 1200)" stroke="#c5d4ed" fill="none">
+    <polygon points="0,-60 52,-30 52,30 0,60 -52,30 -52,-30" stroke-width="0.55" opacity="0.22"/>
+    <polygon points="0,-42 36.4,-21 36.4,21 0,42 -36.4,21 -36.4,-21" stroke-width="0.62" opacity="0.30"/>
+    <polygon points="0,-26 22.5,-13 22.5,13 0,26 -22.5,13 -22.5,-13" stroke-width="0.7" opacity="0.42"/>
+  </g>
+
+  <!-- === Flowing diagonal lines === -->
+  <g stroke-linecap="round">
+    <line x1="-10" y1="180" x2="180" y2="340" stroke="#b8d0e3" stroke-width="0.6" opacity="0.25"/>
+    <line x1="30" y1="220" x2="230" y2="390" stroke="#c5d4ed" stroke-width="0.5" opacity="0.2"/>
+    <line x1="80" y1="270" x2="290" y2="450" stroke="#d0dde9" stroke-width="0.45" opacity="0.18"/>
+
+    <line x1="520" y1="80" x2="650" y2="220" stroke="#c5d4ed" stroke-width="0.5" opacity="0.22"/>
+    <line x1="550" y1="130" x2="690" y2="280" stroke="#d0dde9" stroke-width="0.45" opacity="0.18"/>
+    <line x1="580" y1="190" x2="700" y2="350" stroke="#b8d0e3" stroke-width="0.4" opacity="0.15"/>
+
+    <line x1="20" y1="980" x2="170" y2="1080" stroke="#d0dde9" stroke-width="0.45" opacity="0.2"/>
+    <line x1="500" y1="950" x2="640" y2="1060" stroke="#c5d4ed" stroke-width="0.4" opacity="0.16"/>
+    <line x1="250" y1="1250" x2="420" y2="1340" stroke="#b8d0e3" stroke-width="0.4" opacity="0.18"/>
+  </g>
+
+  <!-- === Dot accents === -->
+  <g fill="#a8c4dd">
+    <circle cx="200" cy="160" r="1.2" opacity="0.4"/>
+    <circle cx="480" cy="380" r="1.4" opacity="0.32"/>
+    <circle cx="80" cy="520" r="1" opacity="0.28"/>
+    <circle cx="580" cy="620" r="1.2" opacity="0.25"/>
+    <circle cx="320" cy="1280" r="1.3" opacity="0.34"/>
+    <circle cx="650" cy="1050" r="1.1" opacity="0.26"/>
+    <circle cx="40" cy="800" r="1" opacity="0.22"/>
+  </g>
+  <g fill="#c5d4ed">
+    <circle cx="400" cy="120" r="1.2" opacity="0.32"/>
+    <circle cx="150" cy="380" r="1.1" opacity="0.26"/>
+    <circle cx="530" cy="900" r="1.3" opacity="0.24"/>
+    <circle cx="280" cy="1180" r="1" opacity="0.28"/>
+    <circle cx="620" cy="1350" r="1.2" opacity="0.2"/>
+  </g>
+
+  <!-- === Subtle arcs === -->
+  <path d="M-20,600 Q150,500 300,620" stroke="#c5d4ed" stroke-width="0.45" opacity="0.18" fill="none"/>
+  <path d="M450,200 Q580,320 680,280" stroke="#d0dde9" stroke-width="0.4" opacity="0.14" fill="none"/>
+  <path d="M100,1300 Q250,1220 400,1320" stroke="#b8d0e3" stroke-width="0.42" opacity="0.16" fill="none"/>
+</svg>

+ 0 - 0
charge-front/src/utils/date.ts → charge-front/src/pages-charge/utils/date.ts


+ 2 - 2
charge-front/src/utils/uploader.ts → charge-front/src/pages-charge/utils/uploader.ts

@@ -1,5 +1,5 @@
-import { host } from "../utils/constant";
-import Http from "../utils/http";
+import { host } from "../../utils/constant";
+import Http from "../../utils/http";
 const uploaderHttp = new Http(host);
 
 type UploadCallback = {

+ 1 - 1
charge-front/src/pages-user/profile/profile.vue

@@ -44,7 +44,7 @@
 <script setup lang="ts">
 import { clearToken } from "../../api/auth";
 import { fetchProfile, updateProfile, logout } from "../../api/user";
-import { upload } from "../../utils/uploader";
+import { upload } from "../utils/uploader";
 import { onLoad, onShow } from "@dcloudio/uni-app";
 import { ref } from "vue";
 const avatar = ref<string>();

+ 151 - 0
charge-front/src/pages-user/utils/uploader.ts

@@ -0,0 +1,151 @@
+import { host } from "../../utils/constant";
+import Http from "../../utils/http";
+const uploaderHttp = new Http(host);
+
+type UploadCallback = {
+  onSuccess?(result: { url: string }): void;
+  onFail?(error: any): void;
+  /** [onStart]
+   *
+   * 开始上传回调函数,返回微信UploadTask
+   *
+   */
+  onStart?(task: any): void;
+  onProgressUpdate?(progress: any): void;
+};
+
+type UploadItem = {
+  filePath: string;
+  callback: UploadCallback;
+};
+
+// 上传并行控制
+const UPLOAD_PARALLEL_COUNT = 2;
+const UPLOAD_QUEUE: Array<UploadItem> = [];
+
+// 单独上传一个并限制在上传并行数量中
+export function uploadByQueue(filePath: string, callback: UploadCallback) {
+  if (UPLOAD_QUEUE.length >= UPLOAD_PARALLEL_COUNT) {
+    UPLOAD_QUEUE.push({
+      filePath,
+      callback,
+    });
+    return;
+  }
+  upload(filePath, {
+    onFail: callback.onFail,
+    onStart: callback.onStart,
+    onProgressUpdate: callback.onProgressUpdate,
+    onSuccess: (res) => {
+      // 还有待上传的
+      if (UPLOAD_QUEUE.length) {
+        const item = UPLOAD_QUEUE.shift();
+        if (item) {
+          uploadByQueue(item.filePath, item.callback);
+        }
+      }
+      callback.onSuccess && callback.onSuccess(res);
+    },
+  });
+}
+
+// 单独上传一个
+export function upload(filePath: string, callback: UploadCallback): void {
+  uploaderHttp
+    .get("/file/getSts")
+    .then((oss) => {
+      const key =
+        "uniapp-scan-code-" +
+        guid() +
+        filePath.slice(filePath.lastIndexOf("."));
+      const uploadTask = wxUploadFile(
+        oss.host,
+        filePath,
+        {
+          key,
+          policy: oss.policy,
+          OSSAccessKeyId: oss.accesskeyId,
+          expire: oss.expire,
+          signature: oss.signature,
+          success_action_status: "200",
+        },
+        {
+          success: (res: any) => {
+            if (res.statusCode == 200 && /ok/.test(res.errMsg)) {
+              // https://kym-static.oss-cn-shenzhen.aliyuncs.com/uniapp-scan-code-41d308c3-2252-1b46-744a-104808f1c0c3.png
+              callback.onSuccess &&
+                callback.onSuccess({
+                  url: `${oss.host}/${key}`,
+                });
+            } else {
+              callback.onFail &&
+                callback.onFail({
+                  errMsg: `update error(${JSON.stringify(res)})`,
+                });
+            }
+          },
+          fail: callback.onFail,
+          complete: () => {
+            // 取消监听
+            callback.onProgressUpdate &&
+              uploadTask.offProgressUpdate(callback.onProgressUpdate);
+          },
+        }
+      );
+      callback.onStart && callback.onStart(uploadTask);
+      if (callback.onProgressUpdate) {
+        uploadTask.onProgressUpdate(callback.onProgressUpdate);
+      }
+    })
+    .catch(callback.onFail);
+}
+
+function wxUploadFile(
+  url: string,
+  filePath: string,
+  formData: any,
+  callback: any
+) {
+  return uni.uploadFile({
+    url,
+    filePath,
+    header: {
+      // satoken: getApp<any>().globalData.token || "",
+    },
+    name: "file",
+    formData,
+    success: (res) => {
+      callback.success && callback.success(res);
+    },
+    fail: (err) => {
+      if (err && err.errMsg.indexOf("abort") >= 0) {
+        // 主动中止s
+        return;
+      }
+      callback.fail && callback.fail(err);
+    },
+    complete: () => {
+      callback.complete && callback.complete();
+    },
+  });
+}
+
+function guid() {
+  function S4() {
+    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
+  }
+  return (
+    S4() +
+    S4() +
+    "-" +
+    S4() +
+    "-" +
+    S4() +
+    "-" +
+    S4() +
+    "-" +
+    S4() +
+    S4() +
+    S4()
+  );
+}

BIN
charge-front/src/static/images/map-bg.jpg