index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. <view class="one_1">
  5. <input type="text" v-model="searchInfo.title" @input="toInput" placeholder="搜索标题">
  6. </view>
  7. <view class="one_2">
  8. <uni-icons @click="toAdd" class="add" type="plusempty" size="40" color="#007AFF"></uni-icons>
  9. </view>
  10. </view>
  11. <view class="two">
  12. <tabs :tabs="tabs" @tabsChange="tabsChange">
  13. <view class="tabsList">
  14. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  15. <view class="list-scroll-view">
  16. <!-- 瀑布流布局列表 -->
  17. <view class="pubuBox">
  18. <view class="pubuItem">
  19. <view class="list" v-for="(item, index) in list" :key="index" @tap="toInfo(item)">
  20. <image :src="item.file&&item.file.length>0?item.file[0].url:''" mode="widthFix">
  21. </image>
  22. <view class="title"> <!-- 这是没有高度的父盒子(下半部分) -->
  23. <view class="title_1">{{ item.title||'暂无' }}</view>
  24. <view class="title_2">
  25. <view class="left">
  26. {{item.contact_name||'暂无昵称'}}
  27. </view>
  28. <view class="right" @tap.stop="toLike(item)">
  29. <text v-if="item.is_like" class="iconfont icon-aixin1"></text>
  30. <text v-else class="iconfont icon-aixin"></text>
  31. {{item.like_num||'0'}}
  32. </view>
  33. </view>
  34. </view>
  35. <view class="button">
  36. <button size="mini" class="button" @tap.stop="toEdit(item)">修改</button>
  37. <button size="mini" type="warn" @tap.stop="toDel(item)">删除</button>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="is_bottom" v-if="is_bottom">
  43. <text>{{config.bottom_title||'到底了!'}}</text>
  44. </view>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. </tabs>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import tabs from '../../components/tabs/index.vue';
  54. export default {
  55. components: {
  56. tabs
  57. },
  58. data() {
  59. return {
  60. searchInfo: {},
  61. config: {},
  62. user: {},
  63. tabs: {
  64. active: '0',
  65. bgColor: '#ffffff',
  66. menu: []
  67. },
  68. list: [],
  69. total: 0,
  70. skip: 0,
  71. limit: 6,
  72. page: 0,
  73. // 数据是否触底
  74. is_bottom: false,
  75. scrollTop: 0,
  76. }
  77. },
  78. onLoad: async function(e) {
  79. const that = this;
  80. that.searchToken();
  81. that.searchConfig();
  82. await that.searchOther();
  83. },
  84. onShow: async function() {
  85. const that = this;
  86. that.clearPage();
  87. await that.search();
  88. },
  89. onPullDownRefresh: async function() {
  90. const that = this;
  91. that.clearPage();
  92. await that.search();
  93. uni.stopPullDownRefresh();
  94. },
  95. methods: {
  96. searchToken() {
  97. const that = this;
  98. try {
  99. const res = uni.getStorageSync('token');
  100. if (res) that.$set(that, `user`, res);
  101. } catch (e) {
  102. uni.showToast({
  103. title: err.errmsg,
  104. icon: 'error',
  105. duration: 2000
  106. });
  107. }
  108. },
  109. searchConfig() {
  110. const that = this;
  111. try {
  112. const res = uni.getStorageSync('config');
  113. if (res) that.$set(that, `config`, res);
  114. } catch (e) {
  115. uni.showToast({
  116. title: err.errmsg,
  117. icon: 'error',
  118. duration: 2000
  119. });
  120. }
  121. },
  122. async search() {
  123. const that = this;
  124. let info = {
  125. skip: that.skip,
  126. limit: that.limit,
  127. contact: that.user._id,
  128. status: that.tabs.active,
  129. user: that.user._id,
  130. }
  131. const res = await that.$api(`/article/article`, 'GET', {
  132. ...info,
  133. ...that.searchInfo
  134. })
  135. if (res.errcode == '0') {
  136. let list = [...that.list, ...res.data];
  137. that.$set(that, `list`, list)
  138. that.$set(that, `total`, res.total)
  139. } else {
  140. uni.showToast({
  141. title: res.errmsg,
  142. });
  143. }
  144. },
  145. // 选择选项卡
  146. tabsChange(e) {
  147. const that = this;
  148. that.$set(that.tabs, `active`, e.active)
  149. that.clearPage();
  150. that.search()
  151. },
  152. // 查看详情
  153. toInfo(item) {
  154. uni.navigateTo({
  155. url: `/pagesHome/article/index?id=${item.id||item._id}`
  156. })
  157. },
  158. // 输入框
  159. toInput(e) {
  160. const that = this;
  161. if (that.searchInfo.title) that.$set(that.searchInfo, `title`, e.detail.value)
  162. else that.$set(that, `searchInfo`, {})
  163. that.clearPage();
  164. that.search();
  165. },
  166. // 新增
  167. toAdd() {
  168. uni.navigateTo({
  169. url: `/pagesMy/article/add`
  170. })
  171. }, // 修改
  172. toEdit(e) {
  173. uni.navigateTo({
  174. url: `/pagesMy/article/add?id=${e._id}`
  175. })
  176. },
  177. // 取消点赞
  178. async toLike(item) {
  179. const that = this;
  180. let res;
  181. res = await that.$api(`/like/${item.like}`, 'DELETE', {})
  182. if (res.errcode == '0') {
  183. that.clearPage();
  184. that.search()
  185. }
  186. },
  187. // 删除
  188. async toDel(e) {
  189. const that = this;
  190. uni.showModal({
  191. title: '提示',
  192. content: '确定删除该作品吗?',
  193. success: async function(res) {
  194. if (res.confirm) {
  195. const res = await that.$api(`/article/${e._id}`, 'DELETE', {})
  196. if (res.errcode == 0) {
  197. that.clearPage();
  198. that.search();
  199. } else {
  200. uni.showToast({
  201. title: res.errmsg,
  202. icon: 'none'
  203. })
  204. }
  205. }
  206. }
  207. });
  208. },
  209. async searchOther() {
  210. const that = this;
  211. let res;
  212. //状态
  213. res = await that.$api('/dictData', 'GET', {
  214. type: 'exam_status',
  215. is_use: '0'
  216. })
  217. if (res.errcode == '0') {
  218. const menu = res.data.map((item) => {
  219. return {
  220. title: item.label,
  221. active: item.value
  222. }
  223. })
  224. that.$set(that.tabs, `menu`, menu)
  225. }
  226. },
  227. // 分页
  228. toPage(e) {
  229. const that = this;
  230. let list = that.list;
  231. let limit = that.limit;
  232. if (that.total > list.length) {
  233. uni.showLoading({
  234. title: '加载中',
  235. mask: true
  236. })
  237. let page = that.page + 1;
  238. that.$set(that, `page`, page)
  239. let skip = page * limit;
  240. that.$set(that, `skip`, skip)
  241. that.search();
  242. uni.hideLoading();
  243. } else that.$set(that, `is_bottom`, true)
  244. },
  245. toScroll(e) {
  246. const that = this;
  247. let up = that.scrollTop;
  248. that.$set(that, `scrollTop`, e.detail.scrollTop);
  249. let num = Math.sign(up - e.detail.scrollTop);
  250. if (num == 1) that.$set(that, `is_bottom`, false);
  251. },
  252. // 清空列表
  253. clearPage() {
  254. const that = this;
  255. that.$set(that, `list`, [])
  256. that.$set(that, `skip`, 0)
  257. that.$set(that, `limit`, 6)
  258. that.$set(that, `page`, 0)
  259. }
  260. }
  261. }
  262. </script>
  263. <style lang="scss" scoped>
  264. .main {
  265. display: flex;
  266. flex-direction: column;
  267. width: 100vw;
  268. height: 100vh;
  269. .one {
  270. display: flex;
  271. justify-content: center;
  272. align-items: center;
  273. padding: 2vw;
  274. .one_1 {
  275. padding: 0 2vw;
  276. width: 85vw;
  277. input {
  278. padding: 2vw;
  279. background-color: var(--f1Color);
  280. font-size: var(--font14Size);
  281. border-radius: 5px;
  282. }
  283. }
  284. }
  285. .two {
  286. background-color: var(--f9Color);
  287. margin: 2vw 0 0 0;
  288. .tabsList {
  289. position: relative;
  290. width: 100vw;
  291. height: 82vh;
  292. .pubuBox {
  293. padding: 2vw;
  294. }
  295. .pubuItem {
  296. column-count: 2;
  297. column-gap: 2vw;
  298. }
  299. .list {
  300. box-sizing: border-box;
  301. border-radius: 2vw;
  302. overflow: hidden;
  303. background-color: var(--mainColor);
  304. break-inside: avoid;
  305. /*避免在元素内部插入分页符*/
  306. box-sizing: border-box;
  307. margin-bottom: 2vw;
  308. }
  309. .list image {
  310. width: 100%;
  311. }
  312. .title {
  313. padding: 2vw;
  314. .title_1 {
  315. font-size: var(--font14Size);
  316. line-height: 4vw;
  317. text-overflow: -o-ellipsis-lastline;
  318. overflow: hidden;
  319. text-overflow: ellipsis;
  320. display: -webkit-box;
  321. -webkit-line-clamp: 2;
  322. line-clamp: 2;
  323. -webkit-box-orient: vertical;
  324. min-height: 6vw;
  325. max-height: 20vw;
  326. }
  327. .title_2 {
  328. display: flex;
  329. justify-content: space-between;
  330. font-size: var(--font12Size);
  331. color: var(--f69Color);
  332. padding: 1vw 0;
  333. .right {
  334. display: flex;
  335. align-items: center;
  336. text:first-child {
  337. padding: 0 1vw 0 0;
  338. }
  339. }
  340. }
  341. }
  342. .button {
  343. text-align: center;
  344. margin: 0 0 1vw 0;
  345. .button {
  346. background-color: var(--f3CColor);
  347. color: var(--mainColor);
  348. margin: 0 1vw 0 0;
  349. }
  350. }
  351. }
  352. }
  353. }
  354. .scroll-view {
  355. position: absolute;
  356. top: 0;
  357. left: 0;
  358. right: 0;
  359. bottom: 0;
  360. .list-scroll-view {
  361. display: flex;
  362. flex-direction: column;
  363. }
  364. }
  365. .is_bottom {
  366. width: 100%;
  367. text-align: center;
  368. text {
  369. padding: 2vw 0;
  370. display: inline-block;
  371. color: var(--f85Color);
  372. font-size: var(--font14Size);
  373. }
  374. }
  375. </style>