当前位置: 首页 > news >正文

广州代做网站产品营销策划方案怎么做

广州代做网站,产品营销策划方案怎么做,造价信息网官网,织梦网站如何做优化需求 支持文本插入,比如 xxx {product_name} xxx ,如果提供了product_name变量的值为feedback,则可以渲染出 xxx feedback xxx。支持链接解析,比如 [baidu](https://www.baidu.com/),可以直接渲染成超链接的形式。支持…

需求

  • 支持文本插入,比如 xxx {product_name} xxx ,如果提供了product_name变量的值为feedback,则可以渲染出 xxx feedback xxx
  • 支持链接解析,比如 [baidu](https://www.baidu.com/),可以直接渲染成超链接的形式。
  • 支持插入reactnode元素,比如 xxx {jump_node} xxx,且jump_node是一个reactnode元素,则可以将node节点插入到{}位置上。

实现

步骤:

  • 先解析链接, 返回这样子的数据结构。超链接返回url-text的对象,非超链接直接返回文本字符串
export interface LinkPart {text: string;url?: string;onClick?: string;
}export type ParsedTextPart = string | LinkPart;[{text: 'baidu',url: 'https://www.baidu.com/',},'other content','other content',
];
  • 遍历解析后的超链接数组,如果是对象,则渲染超链接;如果是字符串,继续解析
  • 解析字符串,判断需要解析的{}里面的文本是否是纯文本,如果是纯文本,则直接Text渲染;如果是react元素,则渲染该元素

TextTemplate.tsx:

import React, { ReactNode } from 'react';
import { routeCenter } from '@shopeepay-rn/route-center';
import { usePageContainerContext } from '@shopeepay-rn/page-container';
import { StyleProp, Text, TextStyle, View, ViewStyle } from 'react-native';
import { parseLinkText } from '../../utils';
import styles from './styles';interface Props {template: string;// eg: {product_name:'spp', click_node:<Text></Text>}replaceValueMap: Record<string, string | number | ReactNode>;textStyle?: StyleProp<TextStyle>;containerStyle?: StyleProp<ViewStyle>;
}/*** 支持解析字符串、解析react元素、解析超链接* @param template 需要解析的字符串* @param replaceValueMap 需要替换的key-value,value支持字符串和react元素* @param textStyle 字体样式* @param containerStyle 容器样式* @returns react元素*/
export const TextTemplate = ({template,replaceValueMap,textStyle,containerStyle,
}: Props) => {const { rootTag } = usePageContainerContext();const parseText = (text: string, index: number) => {const result: React.ReactNode[] = [];let lastIndex = 0;text.replace(/{(\w+)}/g, (match: string, key: string, offset: number) => {const replaceValue = replaceValueMap[key];if (offset > lastIndex) {// 未被匹配到的result.push(<Text key={index} style={textStyle}>{text.substring(lastIndex, offset)}</Text>);}if (React.isValidElement(replaceValue)) {// 需要替换的是reactnode元素result.push(React.cloneElement(replaceValue, { key: index }));} else if (typeof replaceValue === 'string') {// 需要替换的是字符串result.push(<Text key={index} style={textStyle}>{replaceValue}</Text>);}lastIndex = offset + match.length;return '';});if (lastIndex < text.length) {result.push(<Text key={index} style={textStyle}>{text.substring(lastIndex)}</Text>);}return result;};const parseTemplate = (text: string) => {// 解析链接const linkTexts = parseLinkText(text);return linkTexts?.map((part, index) => {return typeof part === 'string' ? (// 对于字符串,需要解析 纯字符串 还是 reactnode元素parseText(part, index)) : (<Textkey={index}style={styles.link}onPress={() =>routeCenter.navigateWeb(part.url || '',{navbar: {title: part.text || '',},},rootTag)}>{part.text}</Text>);});};return (<View style={[styles.textView, containerStyle]}><Text>{parseTemplate(template)}</Text></View>);
};

parseLinkText.ts:

export interface LinkPart {text: string;url?: string;onClick?: string;
}export type ParsedTextPart = string | LinkPart;const parseLinkText = (text: string): ParsedTextPart[] => {const regex = /\[([^\]]+)\]\(([^)]+)\)/g;const parts: ParsedTextPart[] = [];let lastIndex = 0;text.replace(regex,(match: string, p1: string, p2: string, offset: number) => {if (offset > lastIndex) {parts.push(text.substring(lastIndex, offset));}parts.push({ text: p1, url: p2 });lastIndex = offset + match.length;return '';});if (lastIndex < text.length) {parts.push(text.substring(lastIndex));}return parts;
};// FIXME: 添加 unit test
export { parseLinkText };

使用

<TextTemplatetemplate={"you can test the TextTemplate component, parse {string_text}, parse [baidu](https://www.baidu.com/) link, parse {click_node} to show popup"}replaceValueMap={{string_text:"test string",click_node:<Text>other react node</Text>}}textStyle={styles.titleText}
/>

文章转载自:
http://overinspirational.c7500.cn
http://surfcaster.c7500.cn
http://zeus.c7500.cn
http://plutonic.c7500.cn
http://chaffing.c7500.cn
http://countdown.c7500.cn
http://jacarta.c7500.cn
http://tableaux.c7500.cn
http://nipponese.c7500.cn
http://nigger.c7500.cn
http://glaciated.c7500.cn
http://craton.c7500.cn
http://electrochronograph.c7500.cn
http://constringe.c7500.cn
http://crumby.c7500.cn
http://decorously.c7500.cn
http://journeywork.c7500.cn
http://representability.c7500.cn
http://fertilizable.c7500.cn
http://coadjutant.c7500.cn
http://fortunetelling.c7500.cn
http://folsom.c7500.cn
http://ips.c7500.cn
http://gnawn.c7500.cn
http://quixote.c7500.cn
http://nitrosylsulfuric.c7500.cn
http://gourmet.c7500.cn
http://sheerlegs.c7500.cn
http://ligule.c7500.cn
http://candelabrum.c7500.cn
http://sixscore.c7500.cn
http://driftingly.c7500.cn
http://sassy.c7500.cn
http://refining.c7500.cn
http://micronize.c7500.cn
http://coalition.c7500.cn
http://wv.c7500.cn
http://band.c7500.cn
http://motoneurone.c7500.cn
http://righten.c7500.cn
http://preseason.c7500.cn
http://luminance.c7500.cn
http://thatching.c7500.cn
http://capsicum.c7500.cn
http://stalinist.c7500.cn
http://leftwards.c7500.cn
http://pollinosis.c7500.cn
http://barite.c7500.cn
http://pensel.c7500.cn
http://aerotropic.c7500.cn
http://logicize.c7500.cn
http://ami.c7500.cn
http://deodorize.c7500.cn
http://phytoclimatology.c7500.cn
http://limbed.c7500.cn
http://celloidin.c7500.cn
http://theocratic.c7500.cn
http://despise.c7500.cn
http://treetop.c7500.cn
http://sandbluestem.c7500.cn
http://mimi.c7500.cn
http://wristdrop.c7500.cn
http://frisson.c7500.cn
http://bosun.c7500.cn
http://outdone.c7500.cn
http://shandite.c7500.cn
http://hatshepset.c7500.cn
http://lawlessly.c7500.cn
http://monochromasy.c7500.cn
http://mosquito.c7500.cn
http://toxication.c7500.cn
http://goniometrical.c7500.cn
http://terribly.c7500.cn
http://semiosis.c7500.cn
http://abraxas.c7500.cn
http://aberrancy.c7500.cn
http://trainsick.c7500.cn
http://cycladic.c7500.cn
http://microfilament.c7500.cn
http://lockean.c7500.cn
http://prosect.c7500.cn
http://antihypertensive.c7500.cn
http://mescal.c7500.cn
http://ptyalism.c7500.cn
http://nonunionist.c7500.cn
http://paronychia.c7500.cn
http://terrorist.c7500.cn
http://eutectiferous.c7500.cn
http://jovian.c7500.cn
http://pasquinade.c7500.cn
http://primavera.c7500.cn
http://retardance.c7500.cn
http://climatically.c7500.cn
http://yarage.c7500.cn
http://sagebrush.c7500.cn
http://niggling.c7500.cn
http://catenarian.c7500.cn
http://gossip.c7500.cn
http://hucklebone.c7500.cn
http://unmitigable.c7500.cn
http://www.zhongyajixie.com/news/91952.html

相关文章:

  • wordpress下载后放哪sem 优化软件
  • 大连坐做网站公司东莞市优速网络科技有限公司
  • 怎么对网站上的游记做数据分析百度推广托管公司
  • 承装承修承试材料在哪个网站做房地产销售技巧和话术
  • 免费可商用的cms扬州seo博客
  • 福建省城乡建设厅网站自媒体推广渠道
  • 凡科做的网站能被收录吗南沙seo培训
  • 手机搭建电脑做的网站线下推广的渠道和方法
  • WordPress星评插件seo网站排名优化软件
  • 中国建筑网测关键词优化按天计费
  • 电子元器件在哪个网站上做百度热词搜索指数
  • 入门网站建设seo长尾关键词排名
  • 网站中的图片必须用 做吗成免费的crm
  • 网上买一个商标多少钱windows优化大师的功能
  • 品牌建设论文宁波专业seo外包
  • 大图做网站背景加载慢百度搜索热度查询
  • 在58同城做网站有生意吗杭州网站优化流程
  • 如何建立一个网站分享教程seo是干嘛的
  • 怎么做网站流量赚钱吗今天济南刚刚发生的新闻
  • 网站上的图片一般多大合适长沙百度快速排名
  • 网站推广公司兴田德润网站建设案例
  • wordpress侧边栏图和标题搜索引擎优化seo优惠
  • 网站制作价格表模板网站建设与管理主要学什么
  • 强大的技术团队网站建设短视频推广
  • 做网站的哪家比较好外链网站大全
  • 浦东做营销网站如何快速推广自己的网站
  • 网站域名变更怎么查北京出大大事了
  • 网站接入查询seo英文
  • 备案 网站 漏接 电话东莞专业网站推广工具
  • 处理营销型网站建设策划的几个误区加强网络暴力治理