index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <view class="main">
  3. <view class="info">
  4. <scroll-view scroll-y="true" class="scroll-view">
  5. <view class="list-scroll-view">
  6. <view class="one">
  7. <swiperImg :imgsList='info.file'></swiperImg>
  8. </view>
  9. <view class="two">
  10. <view class="two_1">{{info.title||'暂无标题'}}</view>
  11. <view class="two_2">#{{info.zhType||'暂无类型'}}</view>
  12. <view class="two_3">
  13. <rich-text :nodes="info.content"></rich-text>
  14. </view>
  15. <view class="two_4">发布时间:{{info.create_time}}</view>
  16. </view>
  17. <view class="thr">
  18. <view class="thr_1">评论 {{total}}</view>
  19. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  20. <view class="list-scroll-view">
  21. <view class="thr_2">
  22. <view class="list" v-for="(item,index) in list" :key="index" @tap="toBuy(item)">
  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>
  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"><text class="iconfont icon-aixin"></text>{{like}}</view>
  51. <view class="right_1"><text class="iconfont icon-shoucang1"></text>{{collect}}</view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import swiperImg from '../../components/swiper/index.vue';
  60. export default {
  61. components: {
  62. swiperImg
  63. },
  64. data() {
  65. return {
  66. id: '',
  67. config: {},
  68. user: {},
  69. info: {},
  70. // 评论数量
  71. list: [],
  72. total: 0,
  73. skip: 0,
  74. limit: 15,
  75. page: 0,
  76. // 数据是否触底
  77. is_bottom: false,
  78. scrollTop: 0,
  79. // 评论
  80. content: '',
  81. // 点赞
  82. like: 0,
  83. // 收藏
  84. collect: 0,
  85. // 字典表
  86. typeList: []
  87. }
  88. },
  89. onLoad: async function(e) {
  90. const that = this;
  91. that.$set(that, `id`, e && e.id || '');
  92. that.searchConfig();
  93. that.searchToken();
  94. await that.searchOther();
  95. await that.search();
  96. },
  97. methods: {
  98. searchConfig() {
  99. const that = this;
  100. try {
  101. const res = uni.getStorageSync('config');
  102. if (res) that.$set(that, `config`, res);
  103. } catch (e) {
  104. uni.showToast({
  105. title: err.errmsg,
  106. icon: 'error',
  107. duration: 2000
  108. });
  109. }
  110. },
  111. searchToken() {
  112. const that = this;
  113. try {
  114. const res = uni.getStorageSync('token');
  115. if (res) that.$set(that, `user`, res);
  116. } catch (e) {
  117. uni.showToast({
  118. title: err.errmsg,
  119. icon: 'error',
  120. duration: 2000
  121. });
  122. }
  123. },
  124. // 查询
  125. async search() {
  126. const that = this;
  127. if (that.id) {
  128. let res;
  129. res = await that.$api(`/article/${that.id}`, 'GET', {})
  130. if (res.errcode == '0') {
  131. res.data.content = res.data.content.replace(/\<img/gi, '<img class="rich-img"');
  132. res.data.zhType = that.searchDict(res.data.type, 'type')
  133. that.$set(that, `info`, res.data)
  134. } else {
  135. uni.showToast({
  136. title: res.errmsg,
  137. });
  138. }
  139. // 查看评论
  140. that.searchComment();
  141. }
  142. },
  143. // 查看评论
  144. async searchComment() {
  145. const that = this;
  146. let res;
  147. let info = {
  148. skip: that.skip,
  149. limit: that.limit,
  150. is_use: '0',
  151. status: '1',
  152. }
  153. res = await that.$api(`/comment`, 'GET', {
  154. ...info,
  155. });
  156. if (res.errcode == '0') {
  157. let list = [...that.list, ...res.data];
  158. that.$set(that, `list`, list);
  159. that.$set(that, `total`, res.total)
  160. } else {
  161. uni.showToast({
  162. title: res.errmsg,
  163. icon: 'none'
  164. })
  165. }
  166. },
  167. // 查询字典表
  168. searchDict(e, model) {
  169. const that = this;
  170. let data
  171. if (model == 'type') {
  172. data = that.typeList.find((i) => i.value == e);
  173. if (data) return data.label
  174. else return '暂无'
  175. }
  176. },
  177. // 发送
  178. async toSend(item) {
  179. console.log(item);
  180. },
  181. // 分页
  182. toPage(e) {
  183. const that = this;
  184. let list = that.list;
  185. let limit = that.limit;
  186. if (that.total > list.length) {
  187. uni.showLoading({
  188. title: '加载中',
  189. mask: true
  190. })
  191. let page = that.page + 1;
  192. that.$set(that, `page`, page)
  193. let skip = page * limit;
  194. that.$set(that, `skip`, skip)
  195. that.searchComment();
  196. uni.hideLoading();
  197. } else that.$set(that, `is_bottom`, true)
  198. },
  199. // 触底
  200. toScroll(e) {
  201. const that = this;
  202. let up = that.scrollTop;
  203. that.$set(that, `scrollTop`, e.detail.scrollTop);
  204. let num = Math.sign(up - e.detail.scrollTop);
  205. if (num == 1) that.$set(that, `is_bottom`, false);
  206. },
  207. // 清空列表
  208. clearPage() {
  209. const that = this;
  210. that.$set(that, `list`, [])
  211. that.$set(that, `skip`, 0)
  212. that.$set(that, `limit`, 15)
  213. that.$set(that, `page`, 0)
  214. },
  215. // 查询其他信息
  216. async searchOther() {
  217. const that = this;
  218. let res;
  219. // 查询类型
  220. res = await that.$api(`/dictData`, 'GET', {
  221. type: 'home_tabs',
  222. is_use: '0',
  223. })
  224. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  225. },
  226. }
  227. }
  228. </script>
  229. <style lang="scss">
  230. .main {
  231. display: flex;
  232. flex-direction: column;
  233. box-sizing: border-box;
  234. width: 100vw;
  235. height: 100vh;
  236. .info {
  237. position: relative;
  238. flex-grow: 1;
  239. .two {
  240. padding: 0 2vw;
  241. .two_1 {
  242. font-weight: bold;
  243. font-size: var(--font16Size);
  244. }
  245. .two_2 {
  246. padding: 1vw;
  247. font-size: var(--font14Size);
  248. color: var(--f3CColor);
  249. }
  250. .two_3 {
  251. .rich-img {
  252. width: 100% !important;
  253. display: block;
  254. }
  255. }
  256. .two_4 {
  257. padding: 2vw;
  258. font-size: var(--font12Size);
  259. color: var(--f99Color);
  260. border-bottom: 1px solid var(--f9Color);
  261. }
  262. }
  263. .thr {
  264. .thr_1 {
  265. padding: 2vw 4vw;
  266. font-weight: 500;
  267. font-size: var(--font15Size);
  268. border-bottom: 1px solid var(--f9Color);
  269. }
  270. }
  271. }
  272. .foot {
  273. padding: 2vw;
  274. background-color: var(--mainColor);
  275. .foot_1 {
  276. display: flex;
  277. justify-content: space-between;
  278. align-items: center;
  279. .left {
  280. .is-input-border {
  281. border-radius: 45px;
  282. }
  283. }
  284. .right {
  285. width: 40%;
  286. display: flex;
  287. justify-content: space-around;
  288. padding: 2vw;
  289. .right_1 {
  290. display: flex;
  291. align-items: center;
  292. font-size: var(--font18Szie);
  293. .iconfont {
  294. padding: 0 1vw;
  295. font-size: 22px;
  296. }
  297. }
  298. }
  299. }
  300. }
  301. }
  302. .scroll-view {
  303. position: absolute;
  304. top: 0;
  305. left: 0;
  306. right: 0;
  307. bottom: 0;
  308. .list-scroll-view {
  309. display: flex;
  310. flex-direction: column;
  311. }
  312. }
  313. .is_bottom {
  314. width: 100%;
  315. text-align: center;
  316. text {
  317. padding: 2vw 0;
  318. display: inline-block;
  319. color: var(--f85Color);
  320. font-size: var(--font14Size);
  321. }
  322. }
  323. </style>