index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. searchInfo: {},
  48. config: {},
  49. user: {},
  50. tabs: {
  51. active: '0',
  52. bgColor: '#ffffff',
  53. menu: []
  54. },
  55. list: [],
  56. total: 0,
  57. skip: 0,
  58. limit: 6,
  59. page: 0,
  60. // 数据是否触底
  61. is_bottom: false,
  62. scrollTop: 0,
  63. }
  64. },
  65. onLoad: async function(e) {
  66. const that = this;
  67. that.searchToken();
  68. that.searchConfig();
  69. await that.searchOther();
  70. },
  71. onShow: async function() {
  72. const that = this;
  73. that.clearPage();
  74. await that.search();
  75. },
  76. onPullDownRefresh: async function() {
  77. const that = this;
  78. that.clearPage();
  79. await that.search();
  80. uni.stopPullDownRefresh();
  81. },
  82. methods: {
  83. searchToken() {
  84. const that = this;
  85. try {
  86. const res = uni.getStorageSync('token');
  87. if (res) that.$set(that, `user`, res);
  88. } catch (e) {
  89. uni.showToast({
  90. title: err.errmsg,
  91. icon: 'error',
  92. duration: 2000
  93. });
  94. }
  95. },
  96. searchConfig() {
  97. const that = this;
  98. try {
  99. const res = uni.getStorageSync('config');
  100. if (res) that.$set(that, `config`, res);
  101. } catch (e) {
  102. uni.showToast({
  103. title: err.errmsg,
  104. icon: 'error',
  105. duration: 2000
  106. });
  107. }
  108. },
  109. async search() {
  110. const that = this;
  111. let info = {
  112. skip: that.skip,
  113. limit: that.limit,
  114. status: that.tabs.active,
  115. user: that.user._id,
  116. }
  117. const res = await that.$api(`/comment`, 'GET', {
  118. ...info,
  119. ...that.searchInfo
  120. })
  121. if (res.errcode == '0') {
  122. let list = [...that.list, ...res.data];
  123. that.$set(that, `list`, list)
  124. that.$set(that, `total`, res.total)
  125. } else {
  126. uni.showToast({
  127. title: res.errmsg,
  128. });
  129. }
  130. },
  131. // 选择选项卡
  132. tabsChange(e) {
  133. const that = this;
  134. that.$set(that.tabs, `active`, e.active)
  135. that.clearPage();
  136. that.search()
  137. },
  138. // 查看详情
  139. toInfo(item) {
  140. uni.navigateTo({
  141. url: `/pagesHome/article/index?id=${item.source._id}`
  142. })
  143. },
  144. // 输入框
  145. toInput(e) {
  146. const that = this;
  147. if (that.searchInfo.title) that.$set(that.searchInfo, `title`, e.detail.value)
  148. else that.$set(that, `searchInfo`, {})
  149. that.clearPage();
  150. that.search();
  151. },
  152. // 删除
  153. async toDel(e) {
  154. const that = this;
  155. uni.showModal({
  156. title: '提示',
  157. content: '确定删除该评论吗?',
  158. success: async function(res) {
  159. if (res.confirm) {
  160. const res = await that.$api(`/comment/${e._id}`, 'DELETE', {})
  161. if (res.errcode == 0) {
  162. that.clearPage();
  163. that.search();
  164. } else {
  165. uni.showToast({
  166. title: res.errmsg,
  167. icon: 'none'
  168. })
  169. }
  170. }
  171. }
  172. });
  173. },
  174. async searchOther() {
  175. const that = this;
  176. let res;
  177. //状态
  178. res = await that.$api('/dictData', 'GET', {
  179. type: 'exam_status',
  180. is_use: '0'
  181. })
  182. if (res.errcode == '0') {
  183. const menu = res.data.map((item) => {
  184. return {
  185. title: item.label,
  186. active: item.value
  187. }
  188. })
  189. that.$set(that.tabs, `menu`, menu)
  190. }
  191. },
  192. // 分页
  193. toPage(e) {
  194. const that = this;
  195. let list = that.list;
  196. let limit = that.limit;
  197. if (that.total > list.length) {
  198. uni.showLoading({
  199. title: '加载中',
  200. mask: true
  201. })
  202. let page = that.page + 1;
  203. that.$set(that, `page`, page)
  204. let skip = page * limit;
  205. that.$set(that, `skip`, skip)
  206. that.search();
  207. uni.hideLoading();
  208. } else that.$set(that, `is_bottom`, true)
  209. console.log(list.length);
  210. },
  211. toScroll(e) {
  212. const that = this;
  213. let up = that.scrollTop;
  214. that.$set(that, `scrollTop`, e.detail.scrollTop);
  215. let num = Math.sign(up - e.detail.scrollTop);
  216. if (num == 1) that.$set(that, `is_bottom`, false);
  217. },
  218. // 清空列表
  219. clearPage() {
  220. const that = this;
  221. that.$set(that, `list`, [])
  222. that.$set(that, `skip`, 0)
  223. that.$set(that, `limit`, 6)
  224. that.$set(that, `page`, 0)
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="scss" scoped>
  230. .main {
  231. display: flex;
  232. flex-direction: column;
  233. width: 100vw;
  234. height: 100vh;
  235. .one {
  236. background-color: var(--f9Color);
  237. margin: 2vw 0 0 0;
  238. .tabsList {
  239. position: relative;
  240. width: 100vw;
  241. height: 90vh;
  242. .list {
  243. background-color: var(--mainColor);
  244. border: 1px solid var(--f5Color);
  245. padding: 2vw;
  246. margin: 2vw 2vw 0 2vw;
  247. border-radius: 5px;
  248. font-size: var(--font12Size);
  249. .list_1 {
  250. padding: 1vw;
  251. }
  252. .list_2 {
  253. display: flex;
  254. padding: 1vw;
  255. border-radius: 5px;
  256. border: 1px solid var(--f9Color);
  257. .left {
  258. width: 15vw;
  259. .image {
  260. width: 100%;
  261. height: 15vw;
  262. }
  263. }
  264. .right {
  265. padding: 2vw;
  266. width: 75vw;
  267. .right_1 {
  268. font-size: var(--font14Size);
  269. padding: 0 0 2px 0;
  270. }
  271. .right_2 {
  272. padding: 0 0 2px 0;
  273. text {
  274. color: var(--f85Color);
  275. }
  276. }
  277. }
  278. }
  279. .button {
  280. text-align: center;
  281. margin: 1vw 0 0 0;
  282. .button {
  283. background-color: var(--f3CColor);
  284. color: var(--mainColor);
  285. margin: 0 1vw 0 0;
  286. }
  287. }
  288. }
  289. }
  290. }
  291. }
  292. .scroll-view {
  293. position: absolute;
  294. top: 0;
  295. left: 0;
  296. right: 0;
  297. bottom: 0;
  298. .list-scroll-view {
  299. display: flex;
  300. flex-direction: column;
  301. }
  302. }
  303. .is_bottom {
  304. width: 100%;
  305. text-align: center;
  306. text {
  307. padding: 2vw 0;
  308. display: inline-block;
  309. color: var(--f85Color);
  310. font-size: var(--font14Size);
  311. }
  312. }
  313. </style>