对图片路径做处理 线上环境使用加速域名
This commit is contained in:
parent
3209e7e26a
commit
845e9bafce
21
main.js
21
main.js
@ -10,6 +10,19 @@ Vue.config.productionTip = false
|
|||||||
import uView from 'uni_modules/uview-ui';
|
import uView from 'uni_modules/uview-ui';
|
||||||
Vue.use(uView);
|
Vue.use(uView);
|
||||||
|
|
||||||
|
// 导入工具函数
|
||||||
|
import { processImageUrl } from './utils/index.js'
|
||||||
|
|
||||||
|
// 添加全局方法 - Vue 2
|
||||||
|
Vue.prototype.$processImage = (url) => {
|
||||||
|
return processImageUrl(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加全局过滤器 - Vue 2
|
||||||
|
Vue.filter('processImage', function(url) {
|
||||||
|
return processImageUrl(url)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
const app = new Vue({
|
const app = new Vue({
|
||||||
...App
|
...App
|
||||||
@ -26,6 +39,14 @@ const app = createApp(App)
|
|||||||
// 安装 uView
|
// 安装 uView
|
||||||
app.use(uView)
|
app.use(uView)
|
||||||
|
|
||||||
|
// 导入工具函数
|
||||||
|
import { processImageUrl } from './utils/index.js'
|
||||||
|
|
||||||
|
// 添加全局方法 - Vue 3
|
||||||
|
app.config.globalProperties.$processImage = (url) => {
|
||||||
|
return processImageUrl(url)
|
||||||
|
}
|
||||||
|
|
||||||
// 挂载多个全局方法
|
// 挂载多个全局方法
|
||||||
app.config.globalProperties.$toast = $toast
|
app.config.globalProperties.$toast = $toast
|
||||||
app.config.globalProperties.$modal = $modal
|
app.config.globalProperties.$modal = $modal
|
||||||
|
|||||||
@ -2,11 +2,15 @@
|
|||||||
const environments = {
|
const environments = {
|
||||||
development: {
|
development: {
|
||||||
apiUrl: 'https://test.hshuishang.com',
|
apiUrl: 'https://test.hshuishang.com',
|
||||||
picUrl: 'https://test.hshuishang.com'
|
picUrl: 'https://test.hshuishang.com',
|
||||||
|
aliyunOssUrl: 'https://wechat-img-file.oss-cn-beijing.aliyuncs.com',
|
||||||
|
staticUrl: 'https://wechat-img-file.oss-cn-beijing.aliyuncs.com'
|
||||||
},
|
},
|
||||||
production: {
|
production: {
|
||||||
apiUrl: 'https://api.hshuishang.com',
|
apiUrl: 'https://api.hshuishang.com',
|
||||||
picUrl: 'https://api.hshuishang.com'
|
picUrl: 'https://api.hshuishang.com',
|
||||||
|
aliyunOssUrl: 'https://wechat-img-file.oss-cn-beijing.aliyuncs.com',
|
||||||
|
staticUrl: 'http://static.hshuishang.com'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -32,6 +36,26 @@ const envConfig = environments[currentEnv] || environments.development;
|
|||||||
|
|
||||||
export const RequsetUrl = envConfig.apiUrl; // 请求地址前缀
|
export const RequsetUrl = envConfig.apiUrl; // 请求地址前缀
|
||||||
export const picUrl = envConfig.picUrl; // 图片地址前缀
|
export const picUrl = envConfig.picUrl; // 图片地址前缀
|
||||||
|
export const aliyunOssUrl = envConfig.aliyunOssUrl; // 阿里云OSS地址
|
||||||
|
export const staticUrl = envConfig.staticUrl; // 静态资源地址
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理图片URL,根据环境自动替换
|
||||||
|
* @param {string} url - 原始图片URL
|
||||||
|
* @returns {string} - 处理后的图片URL
|
||||||
|
*/
|
||||||
|
export const processImageUrl = (url) => {
|
||||||
|
if (!url) return url;
|
||||||
|
|
||||||
|
// 如果URL包含阿里云OSS地址,则根据环境替换
|
||||||
|
if (url.includes(aliyunOssUrl)) {
|
||||||
|
if (currentEnv === 'production') {
|
||||||
|
return url.replace(aliyunOssUrl, staticUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 小程序跳转方法二次封装
|
* @description 小程序跳转方法二次封装
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user