123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <template>
- <view class="main">
- <view class="one">
- <view class="one_1">{{info.name||'暂无'}}</view>
- <view class="one_2">{{info.create_time||'暂无'}}</view>
- </view>
- <view class="two" v-if="info.path">
- <button class="button" type="primary" size="mini" @click="toView(info.path)">更多内容</button>
- </view>
- <view class="thr" v-if="info.file.length>0">
- <swiperImg :imgsList='info.file'></swiperImg>
- </view>
- <view class="four">
- <rich-text :nodes="formatRichText(info.content)"></rich-text>
- </view>
- </view>
- </template>
- <script>
- import swiperImg from '../../components/swiper/index.vue';
- export default {
- components: {
- swiperImg
- },
- data() {
- return {
- id: '',
- user: {},
- info: {
- file: []
- },
- }
- },
- onLoad: async function(e) {
- const that = this;
- that.$set(that, `id`, e && e.id || '');
- that.searchToken();
- that.search();
- },
- methods: {
- searchToken() {
- const that = this;
- try {
- const res = uni.getStorageSync('token');
- if (res) that.$set(that, `user`, res);
- } catch (e) {
- uni.showToast({
- title: err.errmsg,
- icon: 'error',
- duration: 2000
- });
- }
- },
- async search() {
- const that = this;
- if (that.id) {
- const res = await that.$api(`/notice/${that.id}`, 'GET', {})
- if (res.errcode == '0') {
- that.$set(that, `info`, res.data)
- } else {
- uni.showToast({
- title: res.errmsg,
- });
- }
- }
- },
- // 处理富文本
- formatRichText(html) {
- if (html) {
- // 富文本内容格式化
- return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
- // 查找所有的 img 元素
- return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
- '')
- // 删除找到的所有 img 元素中的 style 属性
- }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
- }
- },
- // 查看公告链接
- toView(url) {
- uni.navigateTo({
- url: `/pagesHome/weather/index?url=${url}`
- })
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .main {
- .one {
- padding: 4vw 2vw;
- text-align: center;
- .one_1 {
- padding: 1vw 0;
- font-weight: bold;
- font-size: var(--font16Size);
- }
- .one_2 {
- color: var(--f85Color);
- font-size: var(--font12Size);
- }
- }
- .two {
- text-align: center;
- .button {
- margin: 1vw 0 0 0;
- background-color: var(--f3CColor);
- color: var(--mainColor);
- font-size: var(--font14Size);
- }
- }
- .thr {
- text-align: center;
- padding: 2vw;
- .image {
- width: 50vw;
- height: 50vw;
- }
- }
- .four {
- padding: 2vw;
- }
- }
- </style>
|