diff --git a/common/utils.js b/common/utils.js
index 6f5da6b..ddafdba 100644
--- a/common/utils.js
+++ b/common/utils.js
@@ -14,3 +14,36 @@ export const Debounce = (fn, wait) => {
if (callNow) fn.apply(this, args)
}
}
+
+/**
+ * 处理头像/图片 URL
+ * @param {String} url 图片路径
+ * @param {String} baseUrl 基础路径
+ * @param {String} defaultUrl 默认图片路径
+ */
+export const getHeadImgUrl = (url, baseUrl, defaultUrl = "/static/common/images/avatar_default2.png") => {
+ if (!url) return defaultUrl;
+ if (url.startsWith('http') || url.startsWith('https') || url.startsWith('blob:')) return url;
+
+ // 统一处理反斜杠:将所有的 \ 替换为 /
+ let cleanUrl = url.replace(/\\/g, '/');
+
+ // 处理 baseUrl: 替换反斜杠并去除末尾斜杠
+ let cleanBaseUrl = '';
+ if (baseUrl) {
+ cleanBaseUrl = baseUrl.replace(/\\/g, '/').replace(/\/$/, '');
+ }
+
+ // 情况三:headSculptureUrl = "/UploadImages/tx.jpg"
+ if (cleanUrl.startsWith('/')) {
+ return cleanBaseUrl + cleanUrl;
+ }
+
+ // 情况二:headSculptureUrl = "UploadImages/tx.jpg"
+ if (cleanUrl.includes('/')) {
+ return cleanBaseUrl + '/' + cleanUrl;
+ }
+
+ // 情况一:headSculptureUrl = "tx.jpg"
+ return cleanBaseUrl + '/UploadImages/' + cleanUrl;
+}
diff --git a/main.js b/main.js
index 33b03ad..38e3cf6 100644
--- a/main.js
+++ b/main.js
@@ -2,6 +2,7 @@ import Vue from 'vue';
import App from './App';
import "./static/common/css/font.css"
import common from './static/common/js/common'
+import { getHeadImgUrl } from '@/common/utils.js';
import jweixin from 'jweixin-module'
import {
HubConnectionBuilder,
@@ -27,6 +28,13 @@ var tips = function(title, type, time) {
// 导入公用js
Vue.prototype.$tips = tips
Vue.prototype.common = common
+Vue.prototype.$getHeadImgUrl = function (url, defaultUrl) {
+ let baseUrl = '';
+ if (this.$u && this.$u.http && this.$u.http.config && this.$u.http.config.baseUrl) {
+ baseUrl = this.$u.http.config.baseUrl;
+ }
+ return getHeadImgUrl(url, baseUrl, defaultUrl);
+}
// 导入微信sdk
Vue.prototype.jweixin = jweixin
// 引入全局uView
diff --git a/pages/chat/index.vue b/pages/chat/index.vue
index f2ed716..22b4f95 100644
--- a/pages/chat/index.vue
+++ b/pages/chat/index.vue
@@ -212,19 +212,11 @@ export default {
},
receiverHeadSculptureUrl() {
- if (this.vuex_msgUser.headSculptureUrl) {
- return this.baseUrl + "/" + this.vuex_msgUser.headSculptureUrl;
- }
-
- return "/static/common/images/avatar_default2.png";
+ return this.$getHeadImgUrl(this.vuex_msgUser.headSculptureUrl);
},
headSculptureUrl() {
- if (this.vuex_user.HeadSculptureUrl) {
- return this.baseUrl + "/" + this.vuex_user.HeadSculptureUrl;
- }
-
- return "/static/common/images/avatar_default2.png";
+ return this.$getHeadImgUrl(this.vuex_user.HeadSculptureUrl);
},
},
diff --git a/pages/home/admissions/index.vue b/pages/home/admissions/index.vue
index 255eaf9..feea492 100644
--- a/pages/home/admissions/index.vue
+++ b/pages/home/admissions/index.vue
@@ -26,7 +26,7 @@
>
diff --git a/pages/home/userSetting/index.vue b/pages/home/userSetting/index.vue
index 289711a..92b8fc1 100644
--- a/pages/home/userSetting/index.vue
+++ b/pages/home/userSetting/index.vue
@@ -251,7 +251,7 @@ export default {
this.imageUrl = "";
this.imageValue = [
{
- url: "/static/common/images/avatar_default.jpg",
+ url: "/static/common/images/avatar_default2.png",
extname: "jpg",
name: "",
},