index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <template>
  2. <view class="main">
  3. <view class="info">
  4. <scroll-view scroll-y="true" :scroll-top="scrollTop" class="scroll-view" @scrolltolower="toPage"
  5. @scroll="toScroll">
  6. <view class="list-scroll-view">
  7. <view class="one">
  8. <swiperImg :imgsList='info.file'></swiperImg>
  9. </view>
  10. <view class="two">
  11. <view class="two_1">{{info.title||'暂无标题'}}</view>
  12. <view class="two_2">#{{info.zhType||'暂无类型'}}</view>
  13. <view class="two_3">
  14. <rich-text :nodes="formatRichText(info.content)"></rich-text>
  15. </view>
  16. <view class="two_4">发布时间:{{info.create_time}}</view>
  17. </view>
  18. <view class="thr">
  19. <view class="thr_1">评论 {{total}}</view>
  20. <scroll-view scroll-y="true" class="scroll">
  21. <view class="list-scroll-view">
  22. <view class="list" v-for="(item,index) in list" :key="index">
  23. <image class="image"
  24. :src="item.user_file&&item.user_file.length>0?item.user_file[0].url:'../../static/my.png'"
  25. mode="aspectFill">
  26. </image>
  27. <view class="other">
  28. <view class="name textOver">{{item.user_name||'暂无'}}</view>
  29. <view class="content">{{item.content||'暂无'}}</view>
  30. <view class="name">{{item.create_time||'暂无'}}</view>
  31. </view>
  32. </view>
  33. <view class="is_bottom" v-if="is_bottom">
  34. <text>{{config.bottom_title}}</text>
  35. </view>
  36. </view>
  37. </scroll-view>
  38. </view>
  39. </view>
  40. </scroll-view>
  41. </view>
  42. <view class="foot">
  43. <view class="foot_1">
  44. <view class="left">
  45. <uni-easyinput confirmType="send" prefixIcon="chatbubble" v-model="content" placeholder="说点什么..."
  46. @confirm="toSend">
  47. </uni-easyinput>
  48. </view>
  49. <view class="right">
  50. <view class="right_1">
  51. <text class="iconfont icon-aixin"></text>
  52. <text>{{like||0}}</text>
  53. </view>
  54. <view class="right_1">
  55. <text class="iconfont icon-shoucang1"></text>
  56. <text>{{collect||0}}</text>
  57. </view>
  58. <view class="right_1" @click="pageScroll">
  59. <text class="iconfont icon-pinglun"></text>
  60. <text>{{total||0}}</text>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </template>
  68. <script>
  69. import moment from 'moment';
  70. import swiperImg from '../../components/swiper/index.vue';
  71. export default {
  72. components: {
  73. swiperImg
  74. },
  75. data() {
  76. return {
  77. id: '',
  78. config: {},
  79. user: {},
  80. info: {},
  81. // 评论数量
  82. list: [],
  83. total: 0,
  84. skip: 0,
  85. limit: 6,
  86. page: 0,
  87. // 数据是否触底
  88. is_bottom: false,
  89. scrollTop: 0,
  90. // 评论
  91. content: '',
  92. // 点赞
  93. like: 0,
  94. // 收藏
  95. collect: 0,
  96. // 字典表
  97. typeList: []
  98. }
  99. },
  100. onLoad: async function(e) {
  101. const that = this;
  102. that.$set(that, `id`, e && e.id || '');
  103. that.searchConfig();
  104. that.searchToken();
  105. await that.searchOther();
  106. await that.search();
  107. },
  108. methods: {
  109. async searchConfig() {
  110. const that = this;
  111. let res;
  112. // 基本设置
  113. res = await that.$api(`/config`, 'GET', {});
  114. if (res.errcode == '0') {
  115. that.$set(that, `config`, res.data);
  116. }
  117. },
  118. searchToken() {
  119. const that = this;
  120. try {
  121. const res = uni.getStorageSync('token');
  122. if (res) that.$set(that, `user`, res);
  123. } catch (e) {
  124. uni.showToast({
  125. title: err.errmsg,
  126. icon: 'error',
  127. duration: 2000
  128. });
  129. }
  130. },
  131. // 查询
  132. async search() {
  133. const that = this;
  134. if (that.id) {
  135. let res;
  136. res = await that.$api(`/article/${that.id}`, 'GET', {})
  137. if (res.errcode == '0') {
  138. res.data.zhType = that.searchDict(res.data.type, 'type')
  139. that.$set(that, `info`, res.data)
  140. uni.setNavigationBarTitle({
  141. title: res.data.contact_name
  142. });
  143. } else {
  144. uni.showToast({
  145. title: res.errmsg,
  146. });
  147. }
  148. // 查看评论
  149. that.searchComment();
  150. }
  151. },
  152. // 处理富文本
  153. formatRichText(html) {
  154. // 富文本内容格式化
  155. return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
  156. // 查找所有的 img 元素
  157. return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
  158. '')
  159. // 删除找到的所有 img 元素中的 style 属性
  160. }).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性,并设置宽度为 100%
  161. },
  162. // 查看评论
  163. async searchComment() {
  164. const that = this;
  165. let res;
  166. let info = {
  167. skip: that.skip,
  168. limit: that.limit,
  169. is_use: '0',
  170. status: '1',
  171. source: that.info._id
  172. }
  173. res = await that.$api(`/comment`, 'GET', {
  174. ...info,
  175. });
  176. if (res.errcode == '0') {
  177. for (let val of res.data) {
  178. const user = await that.$api(`/user/${val.user}`, 'GET', {});
  179. if (user.errcode == '0') {
  180. val.user_file = user.data.logo
  181. val.user_name = user.data.name || user.data.nick_name
  182. }
  183. }
  184. let list = [...that.list, ...res.data];
  185. that.$set(that, `list`, list);
  186. that.$set(that, `total`, res.total)
  187. } else {
  188. uni.showToast({
  189. title: res.errmsg,
  190. icon: 'none'
  191. })
  192. }
  193. },
  194. // 查询字典表
  195. searchDict(e, model) {
  196. const that = this;
  197. let data
  198. if (model == 'type') {
  199. data = that.typeList.find((i) => i.value == e);
  200. if (data) return data.label
  201. else return '暂无'
  202. }
  203. },
  204. // 滑动到评论专区
  205. pageScroll() {
  206. this.$set(this, `scrollTop`, 0);
  207. this.$nextTick(() => {
  208. setTimeout(() => {
  209. uni.createSelectorQuery().in(this).select(`.thr`).boundingClientRect(res => {
  210. this.$set(this, `scrollTop`, res.top);
  211. }).exec();
  212. }, 100);
  213. });
  214. },
  215. // 发送
  216. async toSend(content) {
  217. const that = this;
  218. if (that.user && that.user._id) {
  219. const form = {
  220. user: that.user._id,
  221. user_name: that.user.name || that.user.nick_name,
  222. source: that.info._id,
  223. content,
  224. create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
  225. }
  226. let res = await that.$api(`/comment`, 'POST', form);
  227. if (res.errcode == '0') {
  228. uni.showToast({
  229. title: '评论成功 等待审核',
  230. icon: 'none'
  231. })
  232. that.$set(that, `content`, '')
  233. that.searchComment()
  234. } else {
  235. uni.showToast({
  236. title: res.errmsg,
  237. icon: 'none'
  238. })
  239. }
  240. } else {
  241. uni.navigateTo({
  242. url: `/pagesIndex/login/index`
  243. })
  244. }
  245. },
  246. // 分页
  247. toPage(e) {
  248. const that = this;
  249. let list = that.list;
  250. let limit = that.limit;
  251. if (that.total > list.length) {
  252. uni.showLoading({
  253. title: '加载中',
  254. mask: true
  255. })
  256. let page = that.page + 1;
  257. that.$set(that, `page`, page)
  258. let skip = page * limit;
  259. that.$set(that, `skip`, skip)
  260. that.searchComment();
  261. uni.hideLoading();
  262. } else that.$set(that, `is_bottom`, true)
  263. },
  264. // 触底
  265. toScroll(e) {
  266. const that = this;
  267. let up = that.scrollTop;
  268. that.$set(that, `scrollTop`, e.detail.scrollTop);
  269. let num = Math.sign(up - e.detail.scrollTop);
  270. if (num == 1) that.$set(that, `is_bottom`, false);
  271. },
  272. // 清空列表
  273. clearPage() {
  274. const that = this;
  275. that.$set(that, `list`, [])
  276. that.$set(that, `skip`, 0)
  277. that.$set(that, `limit`, 6)
  278. that.$set(that, `page`, 0)
  279. },
  280. // 查询其他信息
  281. async searchOther() {
  282. const that = this;
  283. let res;
  284. // 查询类型
  285. res = await that.$api(`/dictData`, 'GET', {
  286. type: 'home_tabs',
  287. is_use: '0',
  288. })
  289. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  290. },
  291. }
  292. }
  293. </script>
  294. <style lang="scss" scoped>
  295. .main {
  296. display: flex;
  297. flex-direction: column;
  298. box-sizing: border-box;
  299. width: 100vw;
  300. height: 100vh;
  301. .info {
  302. position: relative;
  303. flex-grow: 1;
  304. .two {
  305. padding: 0 2vw;
  306. .two_1 {
  307. font-weight: bold;
  308. font-size: var(--font16Size);
  309. }
  310. .two_2 {
  311. padding: 1vw;
  312. font-size: var(--font14Size);
  313. color: var(--f3CColor);
  314. }
  315. .two_4 {
  316. padding: 3vw 0;
  317. font-size: var(--font12Size);
  318. color: var(--f99Color);
  319. border-bottom: 1px solid var(--f9Color);
  320. }
  321. }
  322. .thr {
  323. .thr_1 {
  324. padding: 2vw 4vw;
  325. font-weight: 500;
  326. font-size: var(--font15Size);
  327. border-bottom: 1px solid var(--f9Color);
  328. }
  329. .list {
  330. display: flex;
  331. align-items: center;
  332. padding: 2vw;
  333. .image {
  334. width: 10vw;
  335. height: 10vw;
  336. border-radius: 10vw;
  337. }
  338. .other {
  339. display: flex;
  340. flex-direction: column;
  341. width: 80vw;
  342. padding: 2vw;
  343. border-bottom: 1px solid var(--f9Color);
  344. font-size: var(--font12Size);
  345. .name {
  346. color: var(--f85Color);
  347. padding: 2px 0;
  348. }
  349. }
  350. }
  351. }
  352. }
  353. .foot {
  354. padding: 2vw;
  355. background-color: var(--mainColor);
  356. .foot_1 {
  357. display: flex;
  358. justify-content: space-between;
  359. align-items: center;
  360. .left {
  361. .is-input-border {
  362. border-radius: 45px;
  363. }
  364. }
  365. .right {
  366. width: 45%;
  367. display: flex;
  368. justify-content: space-around;
  369. .right_1 {
  370. display: flex;
  371. align-items: center;
  372. font-size: var(--font17Szie);
  373. .iconfont {
  374. padding: 0 1vw;
  375. font-size: 18px;
  376. }
  377. }
  378. }
  379. }
  380. }
  381. }
  382. .scroll-view {
  383. position: absolute;
  384. top: 0;
  385. left: 0;
  386. right: 0;
  387. bottom: 0;
  388. .list-scroll-view {
  389. display: flex;
  390. flex-direction: column;
  391. }
  392. }
  393. .is_bottom {
  394. width: 100%;
  395. text-align: center;
  396. text {
  397. padding: 2vw 0;
  398. display: inline-block;
  399. color: var(--f85Color);
  400. font-size: var(--font14Size);
  401. }
  402. }
  403. </style>