1
0
duplikat dari https://github.com/ialley-workshop-open/uni-halo.git synced 2026-06-11 12:49:30 +08:00

refactor: 将页面配置通过插件动态化配置(plugin-uni-halo)

This commit is contained in:
小莫唐尼
2024-06-24 18:59:05 +08:00
orang tua 959acab9c7
melakukan e17edade28
54 mengubah file dengan 5299 tambahan dan 5653 penghapusan
+3 -3
Melihat File
@@ -7,7 +7,7 @@ export const Platform = {
* 检查当前环境是什么环境
*/
export const checkPlatform = (name) => {
return uni.getSystemInfoSync().platform == name;
return uni.getSystemInfoSync().platform === name;
}
// 默认的应用设置
@@ -20,7 +20,7 @@ export const _DefaultAppSettings = {
},
// 布局配置
layout: {
// h_row_col1 = 一行一列
// h_row_col1 = 一行一列
// h_row_col2 = 一行两列
home: 'h_row_col1',
// lr_image_text=左图右文
@@ -51,7 +51,7 @@ export const _DefaultAppSettings = {
},
about: {
showAdmin: false, // 显示后台登录入口
showAllCount: false, // 默认显示所有的统计信息(关于页面)
showAllCount: false, // 默认显示所有的统计信息(关于页面)
},
// 文章配置
article: {
+144 -147
Melihat File
@@ -10,160 +10,157 @@
* 修改时间:
*/
import HaloConfig from '@/config/halo.config.js';
import HaloTokenConfig from '@/config/token.config.js'
import {
logTypes,
logUtils
} from '@/utils/halo.logs.js'
import {getAppConfigs} from '@/config/index.js'
const utils = {
/**
* 检查是否为http/https链接
*/
checkIsUrl: function(s) {
var reg = /^(http(s)?:\/\/)/i;
return reg.test(s)
},
/**
* 检查是否为http/https链接
*/
checkIsUrl: function (s) {
var reg = /^(http(s)?:\/\/)/i;
return reg.test(s)
},
// 检查链接
checkUrl: function(url) {
if (!url) return '';
if (!this.checkIsUrl(url)) return HaloTokenConfig.BASE_API + url;
return url
},
// 检查链接
checkUrl: function (url) {
if (!url) return '';
if (!this.checkIsUrl(url)) return HaloTokenConfig.BASE_API + url;
return url
},
// 检查封面图
checkThumbnailUrl: function(thumbnail, mustRealUrl = false) {
if (!thumbnail && mustRealUrl) {
return HaloConfig.defaultStaticThumbnailUrl
}
let _url = HaloConfig.defaultThumbnailUrl
if (_url) {
if (_url.indexOf('?') == -1) {
_url += `?next-v=${new Date().getTime()}`
} else {
_url += `&next-v=${new Date().getTime()}`
}
}
if (!thumbnail) return _url;
if (!this.checkIsUrl(thumbnail)) return HaloTokenConfig.BASE_API + thumbnail;
return thumbnail
},
// 检查封面图
checkThumbnailUrl: function (thumbnail, mustRealUrl = false) {
if (!thumbnail && mustRealUrl) {
return this.checkUrl(getAppConfigs().imagesConfig.defaultStaticThumbnailUrl);
}
let _url = this.checkUrl(getAppConfigs().imagesConfig.defaultThumbnailUrl);
if (_url) {
if (_url.indexOf('?') === -1) {
_url += `?next-v=${new Date().getTime()}`
} else {
_url += `&next-v=${new Date().getTime()}`
}
}
if (!thumbnail) return _url;
if (!this.checkIsUrl(thumbnail)) return HaloTokenConfig.BASE_API + thumbnail;
return thumbnail
},
// 检查图片
checkImageUrl: function(image) {
let _url = HaloConfig.defaultImageUrl
if (_url) {
if (_url.indexOf('?') == -1) {
_url += `?next-v=${new Date().getTime()}`
} else {
_url += `&next-v=${new Date().getTime()}`
}
}
if (!image) return _url;
if (!this.checkIsUrl(image)) return HaloTokenConfig.BASE_API + image;
return image
},
// 检查图片
checkImageUrl: function (image) {
let _url
this.checkUrl(getAppConfigs().imagesConfig.defaultImageUrl);
if (_url) {
if (_url.indexOf('?') === -1) {
_url += `?next-v=${new Date().getTime()}`
} else {
_url += `&next-v=${new Date().getTime()}`
}
}
if (!image) return _url;
if (!this.checkIsUrl(image)) return HaloTokenConfig.BASE_API + image;
return image
},
// 检查头像
checkAvatarUrl: function(avatar, isAdmin = false) {
if (isAdmin) return HaloConfig.author.avatar;
if (!avatar) {
let _url = HaloConfig.defaultAvatarUrl
if (_url) {
if (_url.indexOf('?') == -1) {
_url += `?next-v=${new Date().getTime()}`
} else {
_url += `&next-v=${new Date().getTime()}`
}
}
return _url;
}
if (!this.checkIsUrl(avatar)) return HaloTokenConfig.BASE_API + avatar;
return avatar
},
// 检查头像
checkAvatarUrl: function (avatar) {
if (!avatar) {
let _url = this.checkUrl(getAppConfigs().imagesConfig.defaultAvatarUrl);
if (_url) {
if (_url.indexOf('?') === -1) {
_url += `?next-v=${new Date().getTime()}`
} else {
_url += `&next-v=${new Date().getTime()}`
}
}
return _url;
}
if (!this.checkIsUrl(avatar)) return HaloTokenConfig.BASE_API + avatar;
return avatar
},
// 检查文件类型
fnCheckIsFileType(type, attachment) {
if (!attachment) return false;
if (!attachment.mediaType) return false;
if (type == 'video') return attachment.mediaType.indexOf('video/') != -1;
else if (type == 'image') return attachment.mediaType.indexOf('image/') != -1;
else return false;
},
groupData: function(arr, fun) {
const groups = {}
arr.forEach((el) => {
const group = fun(el)
groups[group] = groups[group] || []
groups[group].push(el)
})
return Object.keys(groups).map((group) => {
// 更改data的数据结构 可以改变新数据的结构 data即为newData的数组中每个数据的结构
let data = {
groupName: group,
data: groups[group]
}
return data
})
},
/**
* 数据分组
* @param {Object} oldData 数据源
* @param {Object} prop 分组属性
*/
arrayGroupBy: function(oldData, prop) {
const newData = this.groupData(oldData, (item) => {
return item[prop]
})
return newData
},
/**
* 深克隆
* @param {Object} obj 数据源
*/
deepClone(obj) {
var objClone = Array.isArray(obj) ? [] : {};
if (obj && typeof obj === "object") {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
if (obj[key] && typeof obj[key] === "object") {
objClone[key] = this.deepClone(obj[key]);
} else {
objClone[key] = obj[key];
}
}
}
}
return objClone;
},
/**
* 复制内容到剪贴板
* @param {Object} obj 数据源
*/
copyText(content, tips = '复制成功') {
uni.setClipboardData({
data: content,
showToast: false,
success: () => {
if (tips) {
uni.showToast({
icon: 'none',
title: tips
})
}
}
})
},
previewImage(list) {
list = list.map(item => {
return this.checkUrl(item)
})
uni.previewImage({
urls: list,
loop: true
})
}
// 检查文件类型
fnCheckIsFileType(type, attachment) {
if (!attachment) return false;
if (!attachment.mediaType) return false;
if (type === 'video') return attachment.mediaType.indexOf('video/') !== -1;
else if (type === 'image') return attachment.mediaType.indexOf('image/') !== -1;
else return false;
},
groupData: function (arr, fun) {
const groups = {}
arr.forEach((el) => {
const group = fun(el)
groups[group] = groups[group] || []
groups[group].push(el)
})
return Object.keys(groups).map((group) => {
// 更改data的数据结构 可以改变新数据的结构 data即为newData的数组中每个数据的结构
let data = {
groupName: group,
data: groups[group]
}
return data
})
},
/**
* 数据分组
* @param {Object} oldData 数据源
* @param {Object} prop 分组属性
*/
arrayGroupBy: function (oldData, prop) {
const newData = this.groupData(oldData, (item) => {
return item[prop]
})
return newData
},
/**
* 深克隆
* @param {Object} obj 数据源
*/
deepClone(obj) {
var objClone = Array.isArray(obj) ? [] : {};
if (obj && typeof obj === "object") {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
if (obj[key] && typeof obj[key] === "object") {
objClone[key] = this.deepClone(obj[key]);
} else {
objClone[key] = obj[key];
}
}
}
}
return objClone;
},
/**
* 复制内容到剪贴板
* @param {Object} obj 数据源
*/
copyText(content, tips = '复制成功') {
uni.setClipboardData({
data: content,
showToast: false,
success: () => {
if (tips) {
uni.showToast({
icon: 'none',
title: tips
})
}
}
})
},
previewImage(list) {
list = list.map(item => {
return this.checkUrl(item)
})
uni.previewImage({
urls: list,
loop: true
})
}
};