index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. }
  172. res = await that.$api(`/comment`, 'GET', {
  173. ...info,
  174. });
  175. if (res.errcode == '0') {
  176. for (let val of res.data) {
  177. const user = await that.$api(`/user/${val.user}`, 'GET', {});
  178. if (user.errcode == '0') {
  179. val.user_file = user.data.logo
  180. val.user_name = user.data.name || user.data.nick_name
  181. }
  182. }
  183. let list = [...that.list, ...res.data];
  184. that.$set(that, `list`, list);
  185. that.$set(that, `total`, res.total)
  186. } else {
  187. uni.showToast({
  188. title: res.errmsg,
  189. icon: 'none'
  190. })
  191. }
  192. },
  193. // 查询字典表
  194. searchDict(e, model) {
  195. const that = this;
  196. let data
  197. if (model == 'type') {
  198. data = that.typeList.find((i) => i.value == e);
  199. if (data) return data.label
  200. else return '暂无'
  201. }
  202. },
  203. // 滑动到评论专区
  204. pageScroll() {
  205. this.$set(this, `scrollTop`, 0);
  206. this.$nextTick(() => {
  207. setTimeout(() => {
  208. uni.createSelectorQuery().in(this).select(`.thr`).boundingClientRect(res => {
  209. this.$set(this, `scrollTop`, res.top);
  210. }).exec();
  211. }, 100);
  212. });
  213. },
  214. // 发送
  215. async toSend(content) {
  216. const that = this;
  217. if (that.user && that.user._id) {
  218. const form = {
  219. user: that.user._id,
  220. user_name: that.user.name || that.user.nick_name,
  221. source: that.info._id,
  222. content,
  223. create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
  224. }
  225. let res = await that.$api(`/comment`, 'POST', form);
  226. if (res.errcode == '0') {
  227. uni.showToast({
  228. title: '评论成功 等待审核',
  229. icon: 'none'
  230. })
  231. that.$set(that, `content`, '')
  232. that.searchComment()
  233. } else {
  234. uni.showToast({
  235. title: res.errmsg,
  236. icon: 'none'
  237. })
  238. }
  239. } else {
  240. uni.navigateTo({
  241. url: `/pagesIndex/login/index`
  242. })
  243. }
  244. },
  245. // 分页
  246. toPage(e) {
  247. const that = this;
  248. let list = that.list;
  249. let limit = that.limit;
  250. if (that.total > list.length) {
  251. uni.showLoading({
  252. title: '加载中',
  253. mask: true
  254. })
  255. let page = that.page + 1;
  256. that.$set(that, `page`, page)
  257. let skip = page * limit;
  258. that.$set(that, `skip`, skip)
  259. that.searchComment();
  260. uni.hideLoading();
  261. } else that.$set(that, `is_bottom`, true)
  262. },
  263. // 触底
  264. toScroll(e) {
  265. const that = this;
  266. let up = that.scrollTop;
  267. that.$set(that, `scrollTop`, e.detail.scrollTop);
  268. let num = Math.sign(up - e.detail.scrollTop);
  269. if (num == 1) that.$set(that, `is_bottom`, false);
  270. },
  271. // 清空列表
  272. clearPage() {
  273. const that = this;
  274. that.$set(that, `list`, [])
  275. that.$set(that, `skip`, 0)
  276. that.$set(that, `limit`, 6)
  277. that.$set(that, `page`, 0)
  278. },
  279. // 查询其他信息
  280. async searchOther() {
  281. const that = this;
  282. let res;
  283. // 查询类型
  284. res = await that.$api(`/dictData`, 'GET', {
  285. type: 'home_tabs',
  286. is_use: '0',
  287. })
  288. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  289. },
  290. }
  291. }
  292. </script>
  293. <style lang="scss" scoped>
  294. .main {
  295. display: flex;
  296. flex-direction: column;
  297. box-sizing: border-box;
  298. width: 100vw;
  299. height: 100vh;
  300. .info {
  301. position: relative;
  302. flex-grow: 1;
  303. .two {
  304. padding: 0 2vw;
  305. .two_1 {
  306. font-weight: bold;
  307. font-size: var(--font16Size);
  308. }
  309. .two_2 {
  310. padding: 1vw;
  311. font-size: var(--font14Size);
  312. color: var(--f3CColor);
  313. }
  314. .two_4 {
  315. padding: 3vw 0;
  316. font-size: var(--font12Size);
  317. color: var(--f99Color);
  318. border-bottom: 1px solid var(--f9Color);
  319. }
  320. }
  321. .thr {
  322. .thr_1 {
  323. padding: 2vw 4vw;
  324. font-weight: 500;
  325. font-size: var(--font15Size);
  326. border-bottom: 1px solid var(--f9Color);
  327. }
  328. .list {
  329. display: flex;
  330. align-items: center;
  331. padding: 2vw;
  332. .image {
  333. width: 10vw;
  334. height: 10vw;
  335. border-radius: 10vw;
  336. }
  337. .other {
  338. display: flex;
  339. flex-direction: column;
  340. width: 80vw;
  341. padding: 2vw;
  342. border-bottom: 1px solid var(--f9Color);
  343. font-size: var(--font12Size);
  344. .name {
  345. color: var(--f85Color);
  346. padding: 2px 0;
  347. }
  348. }
  349. }
  350. }
  351. }
  352. .foot {
  353. padding: 2vw;
  354. background-color: var(--mainColor);
  355. .foot_1 {
  356. display: flex;
  357. justify-content: space-between;
  358. align-items: center;
  359. .left {
  360. .is-input-border {
  361. border-radius: 45px;
  362. }
  363. }
  364. .right {
  365. width: 45%;
  366. display: flex;
  367. justify-content: space-around;
  368. .right_1 {
  369. display: flex;
  370. align-items: center;
  371. font-size: var(--font17Szie);
  372. .iconfont {
  373. padding: 0 1vw;
  374. font-size: 18px;
  375. }
  376. }
  377. }
  378. }
  379. }
  380. }
  381. .scroll-view {
  382. position: absolute;
  383. top: 0;
  384. left: 0;
  385. right: 0;
  386. bottom: 0;
  387. .list-scroll-view {
  388. display: flex;
  389. flex-direction: column;
  390. }
  391. }
  392. .is_bottom {
  393. width: 100%;
  394. text-align: center;
  395. text {
  396. padding: 2vw 0;
  397. display: inline-block;
  398. color: var(--f85Color);
  399. font-size: var(--font14Size);
  400. }
  401. }
  402. </style>