54 lines
1.3 KiB
Vue
54 lines
1.3 KiB
Vue
<template>
|
||
<view class="body-container">
|
||
<view class="hint">温馨提示:如需编辑或分享文字,您可选中文字,一键复制至微信或文档内进行操作。</view>
|
||
<view class="content">
|
||
<view wx:for="{{txtParagraphs}}" wx:key="index">
|
||
<text selectable="true">{{item}}</text>
|
||
<view style="height: 10px;"></view> <!-- 段落间隔 -->
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
data() {
|
||
return {
|
||
fileUrl: '',
|
||
txtParagraphs: []
|
||
}
|
||
},
|
||
onLoad() {
|
||
this.setData({
|
||
fileUrl: options.filePath
|
||
})
|
||
this.readTxt()
|
||
},
|
||
methods: {
|
||
readTxt() {
|
||
const _self = this
|
||
const fs = uni.getFileSystemManager();
|
||
fs.readFile({
|
||
filePath: _self.data.fileUrl,
|
||
encoding: 'utf8',
|
||
success: (readRes) => {
|
||
const fileContent = readRes.data;
|
||
// 简单示例:按空行拆分段落
|
||
const paragraphs = fileContent.split('\n\n').map((p) => p.trim()).filter((p) => p);
|
||
// 将处理后的段落数据设置到页面数据中
|
||
this.setData({
|
||
txtParagraphs: paragraphs
|
||
});
|
||
},
|
||
fail: (readErr) => {
|
||
console.error('读取txt文件内容失败:', readErr);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style>
|
||
|
||
</style> |