首次完整推送,

V:1.20240808.006
This commit is contained in:
fm453
2024-08-13 18:32:37 +08:00
parent 15be3e9373
commit c62d15b288
939 changed files with 111777 additions and 0 deletions

View File

@ -0,0 +1,68 @@
function parseEditorImage (blocks = []) {
const images = []
if (!Array.isArray(blocks)) {
blocks = [blocks]
}
for (const block of blocks) {
const {insert = {}, attributes = {}} = block
const {'data-custom': custom = ""} = attributes
let parseCustom = custom.split('&').reduce((obj, item) => {
const [key, value] = item.split('=')
if (key && value) {
obj[key] = value
}
return obj
}, {})
images.push({
src: insert.image,
source: parseCustom.source ? parseCustom.source: insert.image
})
}
return images
}
/**
* 解析媒体库/编辑器中的图片
* @param images 图片地址
* @param type {string} 解析类型 media: 媒体库, editor: 编辑器
* @returns {Promise<{src: *, source: *}[]|{src, source: *}[]>}
*/
export async function parseImageUrl (images = [], type = "media") {
if (type === "editor") {
images = parseEditorImage(images).map(item => item.source)
} else {
if (!Array.isArray(images)) {
images = [images]
}
}
if (!images) return null
const tcbFiles = images.filter(item => item.startsWith("cloud://"))
if (tcbFiles.length) {
const res = await uniCloud.getTempFileURL({
fileList: tcbFiles
})
return images.map(image => {
const file = res.fileList.find(item => item.fileID === image)
return {
src: file ? file.tempFileURL : image,
source: image
}
})
} else {
return images.map(image => ({
src: image,
source: image
}))
}
}

View File

@ -0,0 +1,80 @@
export type ParseImageUrlResult = {
src: string
source: string
}
function parseEditorImage (_blocks: any): UTSJSONObject[] {
const images: UTSJSONObject[] = []
let blocks: UTSJSONObject[]
if (!Array.isArray(_blocks)) {
blocks = [_blocks as UTSJSONObject] as UTSJSONObject[]
} else {
blocks = _blocks as UTSJSONObject[]
}
blocks.forEach((block: UTSJSONObject) => {
const insert = block.getJSON('insert')
const attributes = block.getJSON('attributes')
const custom = attributes!.getString('data-custom')
let parseCustom = custom && custom.split('&') ? custom.split('&').reduce((obj: UTSJSONObject, item: string): UTSJSONObject => {
const kv = item.split('=')
if (kv.length > 1) {
obj[kv[0]] = kv[1]
}
return obj
}, {} as UTSJSONObject) : {}
images.push({
src: insert!.getString('image'),
source: parseCustom.getString('source') != null ? parseCustom.getString('source') : insert!.getString('image')
})
})
return images
}
/**
* 解析媒体库/编辑器中的图片
* @param images 图片地址
* @param type {string} 解析类型 media: 媒体库, editor: 编辑器
* @returns {Promise<{src: *, source: *}[]|{src, source: *}[]>}
*/
export async function parseImageUrl (images: any, type: string = "media"): Promise<ParseImageUrlResult[] | null> {
let imagePaths: string[] = []
if (type === "editor") {
imagePaths = parseEditorImage(images).map((item: UTSJSONObject): string => item.getString('source')!)
} else {
if (!Array.isArray(images)) {
imagePaths = [images as string] as string[]
} else {
imagePaths = images
}
}
if (imagePaths.length <= 0) return null
const tcbFiles = imagePaths.filter((item: string): boolean => item.startsWith("cloud://"))
if (tcbFiles.length > 0) {
const res: UniCloudGetTempFileURLResult = await uniCloud.getTempFileURL({
fileList: tcbFiles
})
return imagePaths.map((image: string): ParseImageUrlResult => {
const file = res.fileList.find((item: UniCloudGetTempFileURLResultItem): boolean => item.fileID === image)
return {
src: file ? file.tempFileURL : image,
source: image
} as ParseImageUrlResult
})
} else {
return imagePaths.map((image: string): ParseImageUrlResult => ({
src: image,
source: image
} as ParseImageUrlResult))
}
}

View File

@ -0,0 +1,28 @@
function parseScanResult (scanText) {
const match = scanText.match(/^(.*?):\/\/(.*)/)
if (!match || match.length < 1) {
uni.showToast({
icon: 'none',
title: '未能识别到有效信息'
})
}
const [, protocol, path] = match
switch (protocol) {
case "internallink":
uni.navigateTo({
url: `/${path.replace(/^\//, '')}`,
fail: () => {
uni.showToast({
icon: "none",
title: "访问的路径不存在"
})
}
})
break
}
}
export default parseScanResult

View File

@ -0,0 +1,28 @@
function parseScanResult (scanText: string): void {
const match = scanText.match(/^(.*?):\/\/(.*)/)
if (!match || match.length < 1) {
uni.showToast({
icon: 'none',
title: '未能识别到有效信息'
})
}
const [, protocol, path] = match
switch (protocol) {
case "internallink":
uni.navigateTo({
url: `/${path.replace(/^\//, '')}`,
fail: () => {
uni.showToast({
icon: "none",
title: "访问的路径不存在"
})
}
})
break
}
}
export default parseScanResult

View File

@ -0,0 +1,93 @@
export default function translatePublishTime(timestamp) {
let result = ''
// 获取当前时间
const currentData = new Date()
// 获取发布时间
const date = new Date(timestamp)
// 获取发布年份
const year = date.getFullYear()
// 获取发布月份
const mouth = date.getMonth() + 1
// 获取发布日期
const day = date.getDate()
// 获取发布小时
const hours = date.getHours()
// 获取发布分钟
const minute = date.getMinutes()
// 获取发布秒数
const second = date.getSeconds()
// 获取发布时间戳
const timer = date.getTime()
// 获取当前年份
const currentYear = currentData.getFullYear()
// 获取当前月份
const currentMonth = currentData.getMonth() + 1
// 获取当前日期
const currentDay = currentData.getDate()
// 获取当前小时
const currentHours = currentData.getHours()
// 获取当前分钟
let currentMinute = currentData.getMinutes()
// 获取当前秒数
const currentSecond = currentData.getSeconds()
// 获取当前时间戳
const currentTimer = currentData.getTime()
// 如果时间差小于10秒
if ((currentTimer - timer) < 1000 * 10) {
// 显示刚刚
result = `刚刚`;
// 如果时间差小于60秒
} else if ((currentTimer - timer) < 1000 * 60) {
// 如果当前分钟大于发布分钟
if (currentMinute > minute) {
// 显示秒数差
result = `${(((currentMinute - minute) * 60) + currentSecond - second)}秒前`;
} else {
// 显示秒数差
result = `${(currentSecond - second)}秒前`;
}
// 如果时间差小于1小时
} else if ((currentTimer - timer) < 1000 * (60 * 60)) {
// 如果当前小时大于发布小时
if (currentHours > hours) {
// 显示分钟差
result = `${(((currentHours - hours) * 60) + currentMinute - minute)}分钟前`;
} else {
// 修改 昨天发布的文章时间会出现负数
// 如果当前分钟小于发布分钟
if (currentMinute < minute) {
// 当前分钟加60
currentMinute += 60
}
// 显示分钟差
result = `${(currentMinute - minute)}分钟前`;
}
// 如果时间差小于1天
} else if ((currentTimer - timer) < 1000 * (24 * 60 * 60)) {
// 如果当前日期大于发布日期
if (currentDay > day) {
// 显示小时差
result = `${((currentDay - day) * 24 + currentHours - hours)}小时前`;
} else {
// 修改 跨月-昨天发布的文章时间会出现负数
// 如果当前月份不等于发布月份
if (currentMonth !== mouth) {
// 显示小时差
result = `${(24 + currentHours - hours)}小时前`;
} else {
// 显示小时差
result = `${(currentHours - hours)}小时前`;
}
}
// 如果发布年份等于当前年份
} else if (currentYear === year) {
// 显示月份和日期
result = `${mouth}${day}`;
} else {
// 显示年份、月份和日期
result = `${year}${mouth}${day}`;
}
return result // 返回结果
}

View File

@ -0,0 +1,93 @@
export default function translatePublishTime(timestamp: number): string {
let result: string
// 获取当前时间
const currentData = new Date()
// 获取发布时间
const date = new Date(timestamp)
// 获取发布年份
const year = date.getFullYear()
// 获取发布月份
const mouth = date.getMonth() + 1
// 获取发布日期
const day = date.getDate()
// 获取发布小时
const hours = date.getHours()
// 获取发布分钟
const minute = date.getMinutes()
// 获取发布秒数
const second = date.getSeconds()
// 获取发布时间戳
const timer = date.getTime()
// 获取当前年份
const currentYear = currentData.getFullYear()
// 获取当前月份
const currentMonth = currentData.getMonth() + 1
// 获取当前日期
const currentDay = currentData.getDate()
// 获取当前小时
const currentHours = currentData.getHours()
// 获取当前分钟
let currentMinute = currentData.getMinutes()
// 获取当前秒数
const currentSecond = currentData.getSeconds()
// 获取当前时间戳
const currentTimer = currentData.getTime()
// 如果时间差小于10秒
if ((currentTimer - timer) < 1000 * 10) {
// 显示刚刚
result = `刚刚`;
// 如果时间差小于60秒
} else if ((currentTimer - timer) < 1000 * 60) {
// 如果当前分钟大于发布分钟
if (currentMinute > minute) {
// 显示秒数差
result = `${(((currentMinute - minute) * 60) + currentSecond - second)}秒前`;
} else {
// 显示秒数差
result = `${(currentSecond - second)}秒前`;
}
// 如果时间差小于1小时
} else if ((currentTimer - timer) < 1000 * (60 * 60)) {
// 如果当前小时大于发布小时
if (currentHours > hours) {
// 显示分钟差
result = `${(((currentHours - hours) * 60) + currentMinute - minute)}分钟前`;
} else {
// 修改 昨天发布的文章时间会出现负数
// 如果当前分钟小于发布分钟
if (currentMinute < minute) {
// 当前分钟加60
currentMinute += 60
}
// 显示分钟差
result = `${(currentMinute - minute)}分钟前`;
}
// 如果时间差小于1天
} else if ((currentTimer - timer) < 1000 * (24 * 60 * 60)) {
// 如果当前日期大于发布日期
if (currentDay > day) {
// 显示小时差
result = `${((currentDay - day) * 24 + currentHours - hours)}小时前`;
} else {
// 修改 跨月-昨天发布的文章时间会出现负数
// 如果当前月份不等于发布月份
if (currentMonth !== mouth) {
// 显示小时差
result = `${(24 + currentHours - hours)}小时前`;
} else {
// 显示小时差
result = `${(currentHours - hours)}小时前`;
}
}
// 如果发布年份等于当前年份
} else if (currentYear === year) {
// 显示月份和日期
result = `${mouth}月${day}日`;
} else {
// 显示年份、月份和日期
result = `${year}年${mouth}月${day}日`;
}
return result // 返回结果
}