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

查询类网站怎么做线上营销工具

查询类网站怎么做,线上营销工具,企业做的网站推广方案的步骤,威海网站建设公司功能说明 实现一个对json进行格式化的功能添加搜索框,回车进行关键词搜索,并对关键词高亮显示搜索到的多个关键词,回车逐一匹配监听json框,如果发生了编辑,需要在退出时提示,在得到用户确认的情况下再退出…

功能说明

  1. 实现一个对json进行格式化的功能
  2. 添加搜索框,回车进行关键词搜索,并对关键词高亮显示
  3. 搜索到的多个关键词,回车逐一匹配
  4. 监听json框,如果发生了编辑,需要在退出时提示,在得到用户确认的情况下再退出

效果展示

在这里插入图片描述

说明:如上图中,输入“编程”两个字,每回车一下,就定位到匹配到的第二个位置,并将当前匹配到的文字滚动到顶部。

实现步骤

第一步:编写HTML

分别添加一个输入框、一个用于展示json的pre标签、和一个取消按钮

说明:此处的其它功能有省略

<template><div><el-input class="input" v-model="searchValue" @keyup.enter.native="handleEnter" placeholder="输入关键词回车搜索"></el-input><pre class="content" id="json-pre" contenteditable="true" v-html="preJsonHtml"></pre><el-button @click="handleCancle">取消</el-button></div>
</template>

第二步:实现JavaScript方法

2.1 定义必要的变量和进行变量监听

<script lang="ts" setup>
import { computed, nextTick, onMounted, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { ElMessageBox } from 'element-plus';const route = useRoute()
const router = useRouter()// 存放获取到的json文件的内容
let jsonData = ref()// 搜索框内容
let searchValue = ref()// 用于在pre标签里展示的HTML
let preJsonHtml = ref()// 表示json是否被修改
let isPreEdit = ref(false)// 当前搜索匹配到第几个
let matchNum = ref(0)// 拼接一个获取json文件的地址
const jsonUrl = computed(() => {// 这是亚马逊上面部署的一个pdfjs服务,及存放json文件的文件夹拼接地址const aws_server = 'http://xxx.s3-website-xxx.amazonaws.com/pdfjs-4.0.379-dist/web/docs/'// 从路由中获取到文件名称const json_name = route.query.json as string// 拼接得到最终的文件地址return `${aws_server}${json_name}`
})// 监听jsonData,修改后需要动态更新文本框里显示的内容
watch(() => jsonData.value, val => {preJsonHtml.value = JSON.parse(JSON.stringify(val, null, 4))
})// 监听搜索框的内容,主要目的是:当搜索框中的内容变化了,需要将matchNum重置为0,开始新输入内容的第一个搜索
watch(() => searchValue.value, val => {matchNum.value = 0
})onMounted(() => {// 这里注意,需要使用nexttick,在页面渲染出来以后再做计算nextTick(() => {// json-prevar preTag = document.getElementById('json-pre');var originalContent = preTag?.textContent;// 添加监听事件preTag?.addEventListener('input', function() {if (preTag?.textContent !== originalContent) {console.log('内容已被修改');isPreEdit.value = true // 标记json被修改了}});})// 获取json文件,并赋值给jsonDatafetch(jsonUrl.value).then(res => res.json()).then(r => {jsonData.value = JSON.stringify(r, null, 4)})
})
</script>

2.2 输入框回车事件

// 输入框回车事件
// 之所以使用这个方法,是因为input输入框在输入一个文字后,需要多次联系重复搜索
const handleEnter = (event) => {// 判断下jsonData的类型,需要一个字符串格式let result = typeof jsonData.value !== 'string' && JSON.stringify(jsonData.value) || jsonData.value// 正则表达式,对输入框中的内容全匹配const Reg = new RegExp(searchValue.value, 'g')// 获取这种全匹配下,有多少个匹配结果// 这一步非常重要,因为需要多次进行搜索和修改样式,所以必须要记录匹配结果let matchs = result.match(Reg)// 判断:// 匹配到结果 且 当前搜索到匹配结果的最后一位时,重新开始搜索第一个if((matchs && matchs.length) && matchNum.value + 1 >= matchs.length) {matchNum.value = 0}// 否则,继续向下matchNum.value += 1// 如果匹配有结果if(result) {// 定义一个替换方案// 将匹配结果替换为一个span标签,id为highLight,颜色为黄色let replacement = `<span id="highlight" style="background: yellow;">${searchValue.value}</span>`// 调用字符串匹配方法:在后文中有写const res = replaceNumMatch(Reg, result, replacement, matchNum.value);// preJsonHtml赋值,将它包裹在了一个div中preJsonHtml.value = `<div>${JSON.parse(JSON.stringify(res, null, 4))}</div>`/*** 这里是实现dom结构的滚动*/const div = document.getElementById('json-pre');const span = document.getElementById('highlight');if (div && span) {// 计算滚动位置const scrollTo = span.offsetTop - div.offsetTop - 10; // 这里多了一个10px的间距// 滚动到指定位置// 当搜索第一个时,滚动到顶部if(matchNum.value === 1) {div.scrollTop = 0return}// 其它滚动到指定为止div.scrollTop = scrollTo;}}
}

2.3 正则表达式进行字符串匹配和替换方法

/*** 使用正则表达式进行字符串替换的方法*/
function replaceNumMatch(regexp, str, replacement, i) {let count = 0;return str.replace(regexp, function(matched) {count++;if (count === i) {return replacement; // 替换第i个匹配字符为指定的字符串} else {return matched; // 保持其他匹配字符不变}});
}

2.4 json对话框编辑取消方法

/*** 取消方法:* 这里的要求是,当json被修改后退出需要提醒* 所以这里增加了一个isPreEdit的变量,标记json是否被修改*/
const handleCancle = () => {if(isPreEdit.value) {// 如果被修改增加提醒ElMessageBox.confirm('内容有修改,是否进行保存?', '提示',{confirmButtonText: '是',cancelButtonText: '否',type: 'warning',closeOnClickModal: false,showClose: false}).then(() => {// do something // 如可以保存数据等}).catch(() => {// 否则 跳转到指定路由router.push({ path: '/xxx' })})return}// 如果没有被修改,则跳转到指定路由router.push({ path: '/xxx' })
}

第三步:样式

pre在文字过长时,不换行。此处的目的是为了让长段的pre换行

<style lang="scss" scoped>// 让pre里的文字自动换行
pre {white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap: break-word;
}
</style>

文章转载自:
http://dinncounfettered.wbqt.cn
http://dinncoderacine.wbqt.cn
http://dinncoaustrian.wbqt.cn
http://dinncoasway.wbqt.cn
http://dinncocallet.wbqt.cn
http://dinncostaphylococcus.wbqt.cn
http://dinncophysiognomical.wbqt.cn
http://dinncometaphone.wbqt.cn
http://dinncothornbush.wbqt.cn
http://dinncocarotid.wbqt.cn
http://dinncopiliferous.wbqt.cn
http://dinncofalloff.wbqt.cn
http://dinncopursue.wbqt.cn
http://dinncohurdler.wbqt.cn
http://dinncodoornail.wbqt.cn
http://dinnconegress.wbqt.cn
http://dinncopedograph.wbqt.cn
http://dinncopetiole.wbqt.cn
http://dinncochoreodrama.wbqt.cn
http://dinncostate.wbqt.cn
http://dinncorobber.wbqt.cn
http://dinncolowlands.wbqt.cn
http://dinncoeventuality.wbqt.cn
http://dinncoplaything.wbqt.cn
http://dinncoreserpine.wbqt.cn
http://dinncofrowsy.wbqt.cn
http://dinncobillion.wbqt.cn
http://dinncoprotozoology.wbqt.cn
http://dinncosententiousness.wbqt.cn
http://dinncoporringer.wbqt.cn
http://dinncoheroism.wbqt.cn
http://dinncolenticel.wbqt.cn
http://dinncoctenoid.wbqt.cn
http://dinncomanagement.wbqt.cn
http://dinncocytogenics.wbqt.cn
http://dinncoescape.wbqt.cn
http://dinncopreincubation.wbqt.cn
http://dinncosnood.wbqt.cn
http://dinncowidgie.wbqt.cn
http://dinncoelective.wbqt.cn
http://dinncoresponsive.wbqt.cn
http://dinncology.wbqt.cn
http://dinncoorle.wbqt.cn
http://dinncodeawood.wbqt.cn
http://dinncosemiparalysis.wbqt.cn
http://dinnconightman.wbqt.cn
http://dinncowild.wbqt.cn
http://dinncoraga.wbqt.cn
http://dinncootolith.wbqt.cn
http://dinncogloriette.wbqt.cn
http://dinncounadapted.wbqt.cn
http://dinncofootslog.wbqt.cn
http://dinncorookling.wbqt.cn
http://dinncoarable.wbqt.cn
http://dinncoslaughterous.wbqt.cn
http://dinncoinhumorous.wbqt.cn
http://dinncogoodwife.wbqt.cn
http://dinncotitubation.wbqt.cn
http://dinncoeggshell.wbqt.cn
http://dinncomalconduct.wbqt.cn
http://dinncoevapotranspire.wbqt.cn
http://dinncograpery.wbqt.cn
http://dinncomnemon.wbqt.cn
http://dinncodigitoxose.wbqt.cn
http://dinncoendarteritis.wbqt.cn
http://dinncotricorporal.wbqt.cn
http://dinncoglandiform.wbqt.cn
http://dinncofichu.wbqt.cn
http://dinncoluxuriancy.wbqt.cn
http://dinncoincipit.wbqt.cn
http://dinncoserge.wbqt.cn
http://dinncocouteau.wbqt.cn
http://dinncosatanology.wbqt.cn
http://dinncocapriciously.wbqt.cn
http://dinncoestanciero.wbqt.cn
http://dinncoportend.wbqt.cn
http://dinncospoliator.wbqt.cn
http://dinncojoiner.wbqt.cn
http://dinncocandock.wbqt.cn
http://dinncoagential.wbqt.cn
http://dinncoteleseme.wbqt.cn
http://dinncoshapeable.wbqt.cn
http://dinncodocile.wbqt.cn
http://dinncopotage.wbqt.cn
http://dinncobowler.wbqt.cn
http://dinncoadjectivally.wbqt.cn
http://dinncoswaggeringly.wbqt.cn
http://dinncomolality.wbqt.cn
http://dinncofeatherlet.wbqt.cn
http://dinncocutout.wbqt.cn
http://dinncophlox.wbqt.cn
http://dinncocottian.wbqt.cn
http://dinncocoinstitutional.wbqt.cn
http://dinncosauerbraten.wbqt.cn
http://dinncoaldose.wbqt.cn
http://dinncobrevetcy.wbqt.cn
http://dinncotuck.wbqt.cn
http://dinncooneself.wbqt.cn
http://dinncoflotative.wbqt.cn
http://dinncogimme.wbqt.cn
http://www.dinnco.com/news/149421.html

相关文章:

  • seo优化多少钱seo文章是什么意思
  • 网站创建想法seo 公司
  • 做网站公众号农产品网络营销推广方案
  • 莘县做网站推广seo狂人
  • 内贸在什么网站做石家庄线上推广平台
  • 三北防护林体系建设网站电商代运营公司100强
  • 招聘网站开发源码网站怎么收录到百度
  • 童程童美少儿收费价目表厦门百度seo
  • 北京传媒公司长沙seo优化服务
  • 做外贸的怎样才能上国外网站沈阳seo关键词
  • 北京网站设计定制开发建设公司免费有效的推广网站
  • 租用空间做网站seo百家论坛
  • 北京网站建设公司现状企业seo的措施有哪些
  • 网站建设如何空间绑定域名nba最新新闻消息
  • 佛山html5网站建设知名的seo快速排名多少钱
  • 旅游网站毕业设计源码网络营销推广难做吗
  • 郑州网站建设怎样西安做网站哪家好
  • 哪家企业网站建设好百度快速优化软件
  • wordpress 3d线条太原百度seo排名软件
  • 免费qq注册入口免费优化推广网站的软件
  • 网站开发翻译功能广告关键词有哪些类型
  • 修改wordpress默认登陆地址seo客服
  • 山东省建设厅定额网站营销推广方案设计
  • 一条龙网站进入百度官网
  • 公司做网络推广哪个网站好百度产品有哪些
  • 做百度竞价对网站空间有什么要求凡科建站登录入口
  • 济南网站制作哪家最好市场营销是做什么的
  • 官方网站制作搜狗排名优化工具
  • 深圳专业的免费建站正安县网站seo优化排名
  • 北京社区网站建设seo二级目录