From 26fbcc475a5ec2046c5915ee4bc88d5634c253fb Mon Sep 17 00:00:00 2001 From: sunlizhou <296190577@qq.com> Date: Tue, 29 Aug 2023 14:45:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=9B=BE=E7=89=87=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home/components/feature_recommended.tsx | 2 +- src/pages/preview/brand/info/info.module.scss | 2 +- src/pages/preview/brand/info/info.tsx | 8 +++- src/pages/preview/illness/article/article.tsx | 3 +- src/utils/day.ts | 48 +++++++++++++++++++ 5 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 src/utils/day.ts diff --git a/src/pages/home/components/feature_recommended.tsx b/src/pages/home/components/feature_recommended.tsx index 2cd2fc9..d904c24 100644 --- a/src/pages/home/components/feature_recommended.tsx +++ b/src/pages/home/components/feature_recommended.tsx @@ -116,7 +116,7 @@ const FeatureRecommended: FC = (props) => { return props.illness.map(d => ({ id: d.id, imageUrl: '', - description: d.description?.replace(/[^\u4e00-\u9fa5]/gi,"") ?? '暂无描述', + description: d.description || '暂无简介', title: d.name, path: `?id=${d.id}` })) diff --git a/src/pages/preview/brand/info/info.module.scss b/src/pages/preview/brand/info/info.module.scss index 60ed52f..eb2bc6f 100644 --- a/src/pages/preview/brand/info/info.module.scss +++ b/src/pages/preview/brand/info/info.module.scss @@ -55,7 +55,7 @@ page{ .image{ width: 172rpx; height:128rpx; - background-color: pink; + background-color: #eee; border-radius: 8rpx; } .leftBox{ diff --git a/src/pages/preview/brand/info/info.tsx b/src/pages/preview/brand/info/info.tsx index 0850cb4..b7bced8 100644 --- a/src/pages/preview/brand/info/info.tsx +++ b/src/pages/preview/brand/info/info.tsx @@ -5,6 +5,8 @@ import styles from './info.module.scss' import Taro, {useReachBottom, useRouter} from "@tarojs/taro"; import LineEllipsis from "@/components/textCollapse/collapse"; import Empty from "@/components/empty/empty"; +import Img from "@/components/image/image"; +import {rfc33392time} from "@/utils/day"; type Params = { id: number @@ -116,9 +118,11 @@ const BrandInfo: FC = () => { {i.title} - {i.created_at} {i.page_view}阅读 + {rfc33392time(i.created_at)} {i.page_view}阅读 + + + - {/**/} ) diff --git a/src/pages/preview/illness/article/article.tsx b/src/pages/preview/illness/article/article.tsx index 9da4689..c45b470 100644 --- a/src/pages/preview/illness/article/article.tsx +++ b/src/pages/preview/illness/article/article.tsx @@ -1,4 +1,4 @@ -import {FC, useEffect, useMemo, useState} from "react"; +import {FC, useEffect, useMemo, useRef, useState} from "react"; import {Image, PageContainer, Text, View} from "@tarojs/components"; import Taro, {useRouter} from "@tarojs/taro"; import {ArticleRecord, brandApi} from "@/api"; @@ -13,6 +13,7 @@ const article:FC = () => { const [show,setShow] = useState(false) const [articleInfo,setArticleInfo] = useState() const { children, headings } = useMemo(() => parse(articleInfo?.content || ''), [articleInfo]) + const query = Taro.createSelectorQuery() diff --git a/src/utils/day.ts b/src/utils/day.ts new file mode 100644 index 0000000..9025c1a --- /dev/null +++ b/src/utils/day.ts @@ -0,0 +1,48 @@ +/** + * 将 RFC3339 标准转成常用时间格式 + * + * ```js + * rfc33392time('2020-07-31T14:27:10.035542+08:00') + * // 2020-07-31 14:28:12 + * ``` + * + * @param {string} dateStr RFC3339 标准时间字符串 + * @returns {string} 常用时间格式 + */ +export const rfc33392time = (dateStr: string): string => { + const date = new Date(dateStr).toJSON() + return (new Date(+new Date(date) + 8 * 3600 * 1000)) + .toISOString() + .replace(/T/g, ' ') + .replace(/\.[\d]{3}Z/, '') +} + +const TIME_OFFSET = (() => { + const info = (new Date().toString()).match(/GMT\+(\d{2})(\d{2})/) + return `+${info![1]} : ${info![2]}` +})() + +/** + * 将常用时间格式转为 RFC3339 标准 + * + * ```js + * time2rfc3339('2020-07-31 14:28:12') + * // 2020-07-31T14:27:10.035542+08:00 + * ``` + * + * @param {string} date 常用时间格式 + * @returns {string} RFC3339 标准时间 + */ +export function time2rfc3339(date: string) { + const time = new Date(date) + const y = time.getFullYear() + const m = time.getMonth() + 1 < 10 ? `0${time.getMonth() + 1}` : (time.getMonth() + 1) + const d = time.getDate() < 10 ? `0${time.getDate()}` : time.getDate() + const hh = time.getHours() < 10 ? `0${time.getHours()}` : time.getHours() + const mm = time.getMinutes() < 10 ? `0${time.getMinutes()}` : time.getMinutes() + const ss = time.getSeconds() < 10 ? `0${time.getSeconds()}` : time.getSeconds() + // const endDate = y + '-' + m + '-' + d + ' ' + hh + ':' + mm + ':' + ss + // endDate = endDate.replace(/\s+/g, 'T') + '+08:00' + // return endDate + return `${y}-${m}-${d}T${hh}:${mm}:${ss}${TIME_OFFSET}` +}