feat: 添加 toHttpsUrl 函数以确保 iframe 地址使用 https 协议,避免 Mixed Content 问题

This commit is contained in:
吴昊天 2026-09-28 17:17:23 +08:00
parent 9e2ae344c8
commit 39c657b4b6
4 changed files with 20 additions and 7 deletions

View File

@ -199,7 +199,7 @@ import {
import QRCode from '@/vendor/qrcodejs2';
import goodClass from './goodClass';
import users from './users';
import { getCookies, setCookies } from '@/libs/util';
import { getCookies, setCookies, toHttpsUrl } from '@/libs/util';
import { modalSure } from '@/utils/public';
import { useMobildConfigStore } from '@diy/store/mobildConfig';
@ -266,7 +266,7 @@ watch(
// created
cardShow.value = route.params.type;
diyProList();
iframeUrl.value = `${Setting.h5BaseURL || location.origin}/pages/index/index?mdType=iframeWindow`;
iframeUrl.value = `${toHttpsUrl(Setting.h5BaseURL) || location.origin}/pages/index/index?mdType=iframeWindow`;
getToken();
onMounted(() => {
@ -327,7 +327,7 @@ function cancel() {
function refreshFrame() {
iframeUrl.value = '';
setTimeout((e) => {
iframeUrl.value = `${Setting.h5BaseURL || location.origin}/pages/index/index?mdType=iframeWindow`;
iframeUrl.value = `${toHttpsUrl(Setting.h5BaseURL) || location.origin}/pages/index/index?mdType=iframeWindow`;
}, 200);
}
function getChildData(e) {

View File

@ -26,6 +26,7 @@ import { ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { diyGetInfo } from '@diy/api';
import Setting from '@/setting';
import { toHttpsUrl } from '@/libs/util';
import rightConfig from '@diy/components/legacy/rightConfig/index';
import links from './links';
import { useMorenStore } from '@diy/store/legacy/moren';
@ -59,7 +60,7 @@ function handleMessage(event) {
{
let pageIdQuery = route.query.id;
pageId.value = parseInt(pageIdQuery);
iframeUrl.value = `${Setting.h5BaseURL || location.origin}/pages/index/index?mdType=iframeWindow`;
iframeUrl.value = `${toHttpsUrl(Setting.h5BaseURL) || location.origin}/pages/index/index?mdType=iframeWindow`;
diyGetInfo(parseInt(pageIdQuery)).then((datas) => {
let data = datas.data.info.value;
upData(data);

View File

@ -26,7 +26,7 @@ import { ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { diyGetInfo, diySave } from '@diy/api';
import rightConfig from '@diy/components/legacy/rightConfig/index';
import { getCookies, setCookies } from '@/libs/util';
import { getCookies, setCookies, toHttpsUrl } from '@/libs/util';
import { useMorenStore } from '@diy/store/legacy/moren';
import Setting from '@/setting';
@ -72,9 +72,9 @@ let show = true;
pageId.value = parseInt(routePageId);
let moveLink = getCookies('moveLink');
if (Number(route.query.type) === 1) {
iframeUrl.value = `${moveLink}/pages/index/index?mdType=iframeWindow`;
iframeUrl.value = `${toHttpsUrl(moveLink)}/pages/index/index?mdType=iframeWindow`;
} else {
iframeUrl.value = `${Setting.h5BaseURL || location.origin}/pages/index/index?mdType=iframeWindow`;
iframeUrl.value = `${toHttpsUrl(Setting.h5BaseURL) || location.origin}/pages/index/index?mdType=iframeWindow`;
}
diyGetInfo(parseInt(routePageId)).then((datas) => {
let data = datas.data.info.value;

View File

@ -30,6 +30,18 @@ export const removeCookies = (key) => {
return Cookies.remove(`${packageConfig.name}:${key}`);
};
/**
* 预览 iframe 地址协议自愈:https 页面下把 http 地址升级为 https,避免被 Mixed Content 拦截
* @param {String} url 预览地址(域名或完整地址)
* @returns {String}
*/
export const toHttpsUrl = (url) => {
if (typeof url === 'string' && location.protocol === 'https:' && /^http:\/\//i.test(url)) {
return url.replace(/^http:\/\//i, 'https://');
}
return url;
};
export const hasChild = (item) => {
return item.children && item.children.length !== 0;
};