feat(utils): 添加toHttpsUrl工具函数并应用

添加toHttpsUrl函数用于将http链接转换为https,并在多个组件和store中应用该函数
调整product-container和index页面的高度计算方式
This commit is contained in:
dzq 2025-11-04 16:11:38 +08:00
parent 70bf8121b1
commit a0904da41b
7 changed files with 39 additions and 9 deletions

View File

@ -227,7 +227,8 @@ function handleCheckout() {
<style scoped lang="scss"> <style scoped lang="scss">
.product-container { .product-container {
display: flex; display: flex;
height: 100%; // height: 100%;
height: calc(100vh - 150px);
background: #f7f8fa; background: #f7f8fa;
position: relative; position: relative;
overflow: hidden; overflow: hidden;
@ -272,6 +273,7 @@ function handleCheckout() {
.product-list { .product-list {
flex: 1; flex: 1;
height: calc(100vh - 150px);
padding: 10px; padding: 10px;
background: #ffffff; background: #ffffff;
} }

View File

@ -7,6 +7,7 @@ import { getShopListApi } from '@/api/shop'
import type { ShopEntity } from '@/api/shop/types' import type { ShopEntity } from '@/api/shop/types'
import ProductContainer from './components/product-container.vue'; import ProductContainer from './components/product-container.vue';
import { mpCodeToOpenId } from '@/api/users' import { mpCodeToOpenId } from '@/api/users'
import { toHttpsUrl } from '@/utils'
definePage({ definePage({
style: { style: {
@ -110,7 +111,7 @@ function handleCheckout() {
<view v-for="shop in shopList" :key="shop.shopId" class="shop-col" @click="handleShopSelect(shop.shopId)"> <view v-for="shop in shopList" :key="shop.shopId" class="shop-col" @click="handleShopSelect(shop.shopId)">
<view class="shop-item"> <view class="shop-item">
<wd-img <wd-img
:src="shop.coverImg || '/static/product-image.png'" :src="toHttpsUrl(shop.coverImg) || '/static/product-image.png'"
width="100%" width="100%"
height="80" height="80"
mode="aspectFill" mode="aspectFill"
@ -139,7 +140,8 @@ function handleCheckout() {
.shop-list { .shop-list {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: calc(100vh - 94px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); // height: calc(100vh - 94px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
height: 100vh;
background: #f7f8fa; background: #f7f8fa;
overflow: hidden; overflow: hidden;
@ -152,8 +154,7 @@ function handleCheckout() {
.shop-list-content { .shop-list-content {
flex: 1; flex: 1;
overflow-y: auto; height: calc(100vh - 150px);
overflow-x: hidden;
} }
.shop-prompt { .shop-prompt {
@ -171,10 +172,14 @@ function handleCheckout() {
} }
.shop-row { .shop-row {
overflow-y: auto;
overflow-x: hidden;
padding: 0 8px; padding: 0 8px;
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
gap: 8px; gap: 8px;
flex: 1;
height: calc(100vh - 150px - 60px);
} }
.shop-col { .shop-col {

View File

@ -3,6 +3,7 @@ import { computed, onMounted } from 'vue'
import { useWxStore } from '@/pinia/stores/wx' import { useWxStore } from '@/pinia/stores/wx'
import { useAb98UserStore } from '@/pinia/stores/ab98-user' import { useAb98UserStore } from '@/pinia/stores/ab98-user'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { toHttpsUrl } from '@/utils'
definePage({ definePage({
style: { style: {
@ -20,7 +21,7 @@ const name = computed(() => {
return userName.value || qyName.value || '未知用户' return userName.value || qyName.value || '未知用户'
}) })
const userAvatar = computed(() => face_img.value ? face_img.value : '/static/logo.png') const userAvatar = computed(() => face_img.value ? toHttpsUrl(face_img.value) : '/static/logo.png')
const ab98BalanceInYuan = computed(() => { const ab98BalanceInYuan = computed(() => {
if (ab98User.value && ab98User.value.ab98Balance !== undefined) { if (ab98User.value && ab98User.value.ab98Balance !== undefined) {

View File

@ -2,6 +2,7 @@ import { pinia } from "@/pinia"
import { LoginData } from "@/api/ab98/types" import { LoginData } from "@/api/ab98/types"
import { defineStore } from "pinia" import { defineStore } from "pinia"
import { ref } from "vue" import { ref } from "vue"
import { toHttpsUrl } from "@/utils"
// 本地存储键名常量 // 本地存储键名常量
const STORAGE_KEYS = { const STORAGE_KEYS = {
@ -54,8 +55,8 @@ export const useAb98UserStore = defineStore("ab98User", () => {
* @param data - * @param data -
*/ */
const setUserInfo = (data: LoginData) => { const setUserInfo = (data: LoginData) => {
face_img.value = data.face_img face_img.value = toHttpsUrl(data.face_img)
uni.setStorageSync(STORAGE_KEYS.FACE, encodeURIComponent(data.face_img)) uni.setStorageSync(STORAGE_KEYS.FACE, encodeURIComponent(toHttpsUrl(data.face_img)))
sex.value = data.sex sex.value = data.sex
uni.setStorageSync(STORAGE_KEYS.SEX, encodeURIComponent(data.sex)) uni.setStorageSync(STORAGE_KEYS.SEX, encodeURIComponent(data.sex))
name.value = data.name name.value = data.name

View File

@ -2,6 +2,7 @@ import { ShopEntity } from "@/api/shop/types"
import { pinia } from "@/pinia" import { pinia } from "@/pinia"
import { getShopGoodsApi } from "@/api/shop" import { getShopGoodsApi } from "@/api/shop"
import { defineStore } from "pinia" import { defineStore } from "pinia"
import { toHttpsUrl } from "@/utils"
export interface Product { export interface Product {
id: number // 商品ID id: number // 商品ID
@ -55,7 +56,7 @@ export const useProductStore = defineStore("product", () => {
price: g.price, price: g.price,
stock: g.stock, stock: g.stock,
description: g.goodsDetail || "暂无描述", description: g.goodsDetail || "暂无描述",
image: g.coverImg, image: toHttpsUrl(g.coverImg),
label: g.categoryId, label: g.categoryId,
cellId: g.cellId, cellId: g.cellId,
usageInstruction: g.usageInstruction || "", usageInstruction: g.usageInstruction || "",

View File

@ -1,3 +1,20 @@
/**
* URL中的 http:// 替换为 https://
* @param url URL字符串
* @returns URL字符串
*/
export function toHttpsUrl(url: string): string {
// 严格类型检查
if (typeof url !== 'string') {
return url;
}
// 检查是否以 http:// 开头
if (!/^http:\/\//i.test(url)) {
return url;
}
return url.replace(/^http:\/\//i, 'https://');
}
/** /**
* URL参数解析函数 * URL参数解析函数
* @param url URL字符串 * @param url URL字符串

View File

@ -1,5 +1,8 @@
import { pages, subPackages } from '@/pages.json' import { pages, subPackages } from '@/pages.json'
import { isMpWeixin } from './platform' import { isMpWeixin } from './platform'
import { toHttpsUrl } from './common'
export { toHttpsUrl }
export function getLastPage() { export function getLastPage() {
// getCurrentPages() 至少有1个元素所以不再额外判断 // getCurrentPages() 至少有1个元素所以不再额外判断