index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. <tabs :tabs="tabs" @tabsChange="tabsChange">
  5. <view class="tabsList">
  6. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  7. <view class="list-scroll-view">
  8. <view class="list" v-for="(item, index) in list" :key="index">
  9. <view class="list_1">
  10. {{item.content||'暂无'}}
  11. </view>
  12. <view class="list_2" @tap="toInfo(item)">
  13. <view class="left">
  14. <image class="image"
  15. :src="item.source.file&&item.source.file.length>0?item.source.file[0].url:''"
  16. mode="aspectFill">
  17. </view>
  18. <view class="right">
  19. <view class="right_1 textOver">{{item.source.title||'暂无标题'}}</view>
  20. <view class="right_2"><text>发布人:</text>{{item.source.contact_name||'暂无'}}</view>
  21. <view class="right_2"><text>发布时间:</text>{{item.source.create_time||'暂无'}}
  22. </view>
  23. </view>
  24. </view>
  25. <view class="button">
  26. <button size="mini" type="warn" @tap.stop="toDel(item)">删除</button>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="is_bottom" v-if="is_bottom">
  31. <text>{{config.bottom_title||'到底了!'}}</text>
  32. </view>
  33. </scroll-view>
  34. </view>
  35. </tabs>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import tabs from '../../components/tabs/index.vue';
  41. export default {
  42. components: {
  43. tabs
  44. },
  45. data() {
  46. return {
  47. config: {},
  48. user: {},
  49. tabs: {
  50. active: '0',
  51. bgColor: '#ffffff',
  52. menu: []
  53. },
  54. list: [],
  55. total: 0,
  56. skip: 0,
  57. limit: 6,
  58. page: 0,
  59. // 数据是否触底
  60. is_bottom: false,
  61. scrollTop: 0,
  62. }
  63. },
  64. onLoad: async function(e) {
  65. const that = this;
  66. that.searchToken();
  67. that.searchConfig();
  68. await that.searchOther();
  69. },
  70. onShow: async function() {
  71. const that = this;
  72. that.clearPage();
  73. await that.search();
  74. },
  75. onPullDownRefresh: async function() {
  76. const that = this;
  77. that.clearPage();
  78. await that.search();
  79. uni.stopPullDownRefresh();
  80. },
  81. methods: {
  82. searchToken() {
  83. const that = this;
  84. try {
  85. const res = uni.getStorageSync('token');
  86. if (res) that.$set(that, `user`, res);
  87. } catch (e) {
  88. uni.showToast({
  89. title: err.errmsg,
  90. icon: 'error',
  91. duration: 2000
  92. });
  93. }
  94. },
  95. searchConfig() {
  96. const that = this;
  97. try {
  98. const res = uni.getStorageSync('config');
  99. if (res) that.$set(that, `config`, res);
  100. } catch (e) {
  101. uni.showToast({
  102. title: err.errmsg,
  103. icon: 'error',
  104. duration: 2000
  105. });
  106. }
  107. },
  108. async search() {
  109. const that = this;
  110. let info = {
  111. skip: that.skip,
  112. limit: that.limit,
  113. status: that.tabs.active,
  114. user: that.user._id,
  115. }
  116. const res = await that.$api(`/comment`, 'GET', {
  117. ...info,
  118. })
  119. if (res.errcode == '0') {
  120. let list = [...that.list, ...res.data];
  121. that.$set(that, `list`, list)
  122. that.$set(that, `total`, res.total)
  123. } else {
  124. uni.showToast({
  125. title: res.errmsg,
  126. });
  127. }
  128. },
  129. // 选择选项卡
  130. tabsChange(e) {
  131. const that = this;
  132. that.$set(that.tabs, `active`, e.active)
  133. that.clearPage();
  134. that.search()
  135. },
  136. // 查看详情
  137. toInfo(item) {
  138. uni.navigateTo({
  139. url: `/pagesHome/article/index?id=${item.source._id}`
  140. })
  141. },
  142. // 删除
  143. async toDel(e) {
  144. const that = this;
  145. uni.showModal({
  146. title: '提示',
  147. content: '确定删除该评论吗?',
  148. success: async function(res) {
  149. if (res.confirm) {
  150. const res = await that.$api(`/comment/${e._id}`, 'DELETE', {})
  151. if (res.errcode == 0) {
  152. that.clearPage();
  153. that.search();
  154. } else {
  155. uni.showToast({
  156. title: res.errmsg,
  157. icon: 'none'
  158. })
  159. }
  160. }
  161. }
  162. });
  163. },
  164. async searchOther() {
  165. const that = this;
  166. let res;
  167. //状态
  168. res = await that.$api('/dictData', 'GET', {
  169. type: 'exam_status',
  170. is_use: '0'
  171. })
  172. if (res.errcode == '0') {
  173. const menu = res.data.map((item) => {
  174. return {
  175. title: item.label,
  176. active: item.value
  177. }
  178. })
  179. that.$set(that.tabs, `menu`, menu)
  180. }
  181. },
  182. // 分页
  183. toPage(e) {
  184. const that = this;
  185. let list = that.list;
  186. let limit = that.limit;
  187. if (that.total > list.length) {
  188. uni.showLoading({
  189. title: '加载中',
  190. mask: true
  191. })
  192. let page = that.page + 1;
  193. that.$set(that, `page`, page)
  194. let skip = page * limit;
  195. that.$set(that, `skip`, skip)
  196. that.search();
  197. uni.hideLoading();
  198. } else that.$set(that, `is_bottom`, true)
  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`, 6)
  213. that.$set(that, `page`, 0)
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. .main {
  220. display: flex;
  221. flex-direction: column;
  222. width: 100vw;
  223. height: 100vh;
  224. .one {
  225. background-color: var(--f9Color);
  226. margin: 2vw 0 0 0;
  227. .tabsList {
  228. position: relative;
  229. width: 100vw;
  230. height: 90vh;
  231. .list {
  232. background-color: var(--mainColor);
  233. border: 1px solid var(--f5Color);
  234. padding: 2vw;
  235. margin: 2vw 2vw 0 2vw;
  236. border-radius: 5px;
  237. font-size: var(--font12Size);
  238. .list_1 {
  239. padding: 1vw;
  240. }
  241. .list_2 {
  242. display: flex;
  243. padding: 1vw;
  244. border-radius: 5px;
  245. border: 1px solid var(--f9Color);
  246. .left {
  247. width: 15vw;
  248. .image {
  249. width: 100%;
  250. height: 15vw;
  251. }
  252. }
  253. .right {
  254. padding: 2vw;
  255. width: 75vw;
  256. .right_1 {
  257. font-size: var(--font14Size);
  258. padding: 0 0 2px 0;
  259. }
  260. .right_2 {
  261. padding: 0 0 2px 0;
  262. text {
  263. color: var(--f85Color);
  264. }
  265. }
  266. }
  267. }
  268. .button {
  269. text-align: center;
  270. margin: 1vw 0 0 0;
  271. .button {
  272. background-color: var(--f3CColor);
  273. color: var(--mainColor);
  274. margin: 0 1vw 0 0;
  275. }
  276. }
  277. }
  278. }
  279. }
  280. }
  281. .scroll-view {
  282. position: absolute;
  283. top: 0;
  284. left: 0;
  285. right: 0;
  286. bottom: 0;
  287. .list-scroll-view {
  288. display: flex;
  289. flex-direction: column;
  290. }
  291. }
  292. .is_bottom {
  293. width: 100%;
  294. text-align: center;
  295. text {
  296. padding: 2vw 0;
  297. display: inline-block;
  298. color: var(--f85Color);
  299. font-size: var(--font14Size);
  300. }
  301. }
  302. </style>