網站首頁 編程語言 正文
1、添加樣式
<rich-text class="rich-txt" :nodes="detail"></rich-text>
.rich-txt{
word-break: break-all;
white-space: pre-line;
}
完整代碼示例:
<template>
<view>
<!-- 導航欄 -->
<cu-custom bgColor="bg-white" :isBack="true">
<block slot="content" color="#666666" v-if="!inputShowed">{{$t('cloudData.查詢結果')}}</block>
<block slot="right">
<view class="s-bar" v-if="inputShowed">
<view class="l-pr">
<view class="ll-pr">
<uni-icons class="i-pr" type="search" color="#CCCCCC" size="18" />
<input confirm-type="search" class="s-bar-ipt" placeholder-class="s-bar-ipt-h" :placeholder="$t('common.請輸入適配器編碼/設備名稱')" :value="keywords" :focus="inputShowed" @confirm="inputConfirm" @input="inputChange" />
</view>
<uni-icons class="i-pr" type="clear" color="#CCCCCC" size="16" v-if="keywords" @tap="clearInput" />
</view>
<view class="r-pr" @tap="hideInput">{{$t('common.取消')}}</view>
</view>
<view class="icon-pr" v-else>
<uni-icons class="ic-pr" type="search" color="#666666" size="20" @tap="showInput" />
</view>
</block>
</cu-custom>
<!--列表-->
<mescroll-body class="scrolly" ref="mescrollRef" :up="upOption" @init="mescrollInit" @down="downCallback">
<block v-for="(item, index) in dataList" :key="index">
<tui-collapse :index="index" :current="item.current" :disabled="item.disabled" @click="collapseChange">
<template v-slot:title>
<tui-list-cell class="tlt-pr" :hover="!item.disabled">
<text class="tlt-txt" :class="item.symbol?'bg-yellow':''">{{item.title}}</text>
</tui-list-cell>
</template>
<template v-slot:content>
<view class="cnt-pr" v-if="item.symbol"><rich-text class="rich-txt" :nodes="item.contentSel"></rich-text></view>
<view class="cnt-pr" v-else><text class="rich-txt">{{item.content}}</text></view>
</template>
</tui-collapse>
</block>
</mescroll-body>
</view>
</template>
<script>
import nText from "@/components/n-text/n-text.vue"
import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
export default {
mixins: [MescrollMixin], // 使用mixin
components: {
nText
},
data() {
return {
params: null,
keywords: '',
mescroll: null , //mescroll實例對象
inputShowed: false,
upOption: {
use: false, //關閉上拉加載
},
//所有數據集
dataList: [],
}
},
onLoad(option) {
console.log(option.param)
this.params = option.param;
},
methods: {
//搜索框功能函數
showInput() {
this.inputShowed = true;
},
hideInput() {
this.inputShowed = false;
uni.hideKeyboard(); //強行隱藏鍵盤
//清除標記
this.clearInput();
},
clearInput() {
this.keywords = "";
for (var i = 0; i < this.dataList.length; i++) {
this.dataList[i].symbol = false;
this.dataList[i].contentSel = '';
}
},
inputChange(e) {
this.keywords = e.detail.value;
//關鍵詞搜索
if(this.keywords){
var replaceString = '<span style="color:#f37b1d;font-size:16px;font-weight:bold;">' + this.keywords + "</span>";
this.dataList.map((item) => {
if(item.content.indexOf(this.keywords) > -1){
item.symbol = true;
item.contentSel = item.content.replaceAll(this.keywords, replaceString);
}else{
item.symbol = false;
item.contentSel = '';
}
});
}else{
this.clearInput();
}
},
inputConfirm(e) {
this.keywords = e.detail.value;
},
//可展開列表
collapseChange(e) {
let index = e.index;
let item = this.dataList[index];
item.current = item.current == index ? -1 : index;
},
//下拉刷新
downCallback(){
let params = {
cmuid: uni.getStorageSync('cmuid'),
adaptorCode: 'F06215068025'//this.params.adapterCode
}
this.api.getDatas(params).then(res => {
console.log(res)
if (res.data && res.data.msgCode && res.data.msgCode == "0") {
//聯網成功的回調,隱藏下拉刷新的狀態
this.mescroll.endSuccess();
//處理數據
var datas = res.data.data;
//構建數據集
this.dataList = [];
for (var i = 0; i < datas.length; i++) {
var item = {};
item.title = (i+1) +". "+ datas[i].timestamp;
item.content = JSON.stringify(datas[i]);
item.current = -1;
item.disabled = false;
item.symbol = false;
item.contentSel = '';
this.dataList.push(item);
}
} else {
this.mescroll.endErr();
this.api.showComToast(res.message);
}
}).catch(error => {
//聯網失敗的回調,隱藏下拉刷新的狀態
this.mescroll.endErr();
})
},
}
}
</script>
<style lang="scss">
.s-bar{
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 3rpx 3rpx 3rpx 10rpx;
.l-pr{
width: 85%;
display: flex;
justify-content: space-between;
align-items: center;
border-radius: 30rpx;
background-color: #f2f2f2;
.ll-pr{
flex: 1;
display: flex;
flex-wrap: wrap;
align-items: center;
.s-bar-ipt{
flex: 1;
font-size: 26rpx;
color: black;
}
.s-bar-ipt-h{
flex: 1;
color: #CCCCCC;
font-size: 26rpx;
}
}
.i-pr{
margin: 10rpx;
}
}
.r-pr{
width: 14%;
font-size: 24rpx;
text-align: center;
padding-right: 5rpx;
}
}
.icon-pr{
width: 100%;
display: flex;
flex-wrap: wrap;
flex-direction: row-reverse;
.ic-pr{
margin-right: 25rpx;
}
}
.scrolly{
.tlt-pr{
margin-top: 10rpx;
font-weight: bold;
.tlt-txt{
font-size: 32rpx;
}
}
.cnt-pr{
padding: 10rpx 15rpx;
font-size: 24rpx;
.rich-txt{
word-break: break-all;
white-space: pre-line;
}
}
}
</style>
原文鏈接:https://ly9527.blog.csdn.net/article/details/127689480
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2024-03-24 SpringBoot工具庫:解決SpringBoot2.*版本跨域問題
- 2022-09-13 Python判斷和循環語句的分析與應用_python
- 2023-10-28 C語言中getchar函數詳解看這一篇就夠了(函數功能、使用、返回值)_C 語言
- 2023-03-18 Android?UI動態設置帶有Stroke漸變色背景Drawable_Android
- 2023-03-04 React中實現keepalive組件緩存效果的方法詳解_React
- 2022-11-28 C語言中getchar()函數的用法小結_C 語言
- 2022-03-16 C++中的Lambda函數詳解_C 語言
- 2023-03-25 Python應用之bin文件的制作_python
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支