index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. }
  130. const res = await that.$api(`/article/article`, 'GET', {
  131. ...info,
  132. ...that.searchInfo
  133. })
  134. if (res.errcode == '0') {
  135. let list = [...that.list, ...res.data];
  136. that.$set(that, `list`, list)
  137. that.$set(that, `total`, res.total)
  138. } else {
  139. uni.showToast({
  140. title: res.errmsg,
  141. });
  142. }
  143. },
  144. // 选择选项卡
  145. tabsChange(e) {
  146. const that = this;
  147. that.$set(that.tabs, `active`, e.active)
  148. that.clearPage();
  149. that.search()
  150. },
  151. // 查看详情
  152. toInfo(item) {
  153. uni.navigateTo({
  154. url: `/pagesHome/article/index?id=${item.id||item._id}`
  155. })
  156. },
  157. // 输入框
  158. toInput(e) {
  159. const that = this;
  160. if (that.searchInfo.title) that.$set(that.searchInfo, `title`, e.detail.value)
  161. else that.$set(that, `searchInfo`, {})
  162. that.clearPage();
  163. that.search();
  164. },
  165. // 新增
  166. toAdd() {
  167. uni.navigateTo({
  168. url: `/pagesMy/article/add`
  169. })
  170. }, // 修改
  171. toEdit(e) {
  172. uni.navigateTo({
  173. url: `/pagesMy/article/add?id=${e._id}`
  174. })
  175. },
  176. // 取消点赞
  177. async toLike(item) {
  178. const that = this;
  179. let res;
  180. res = await that.$api(`/like/${item.like}`, 'DELETE', {})
  181. if (res.errcode == '0') {
  182. that.clearPage();
  183. that.search()
  184. }
  185. },
  186. // 删除
  187. async toDel(e) {
  188. const that = this;
  189. uni.showModal({
  190. title: '提示',
  191. content: '确定删除该作品吗?',
  192. success: async function(res) {
  193. if (res.confirm) {
  194. const res = await that.$api(`/article/${e._id}`, 'DELETE', {})
  195. if (res.errcode == 0) {
  196. that.clearPage();
  197. that.search();
  198. } else {
  199. uni.showToast({
  200. title: res.errmsg,
  201. icon: 'none'
  202. })
  203. }
  204. }
  205. }
  206. });
  207. },
  208. async searchOther() {
  209. const that = this;
  210. let res;
  211. //状态
  212. res = await that.$api('/dictData', 'GET', {
  213. type: 'exam_status',
  214. is_use: '0'
  215. })
  216. if (res.errcode == '0') {
  217. const menu = res.data.map((item) => {
  218. return {
  219. title: item.label,
  220. active: item.value
  221. }
  222. })
  223. that.$set(that.tabs, `menu`, menu)
  224. }
  225. },
  226. // 分页
  227. toPage(e) {
  228. const that = this;
  229. let list = that.list;
  230. let limit = that.limit;
  231. if (that.total > list.length) {
  232. uni.showLoading({
  233. title: '加载中',
  234. mask: true
  235. })
  236. let page = that.page + 1;
  237. that.$set(that, `page`, page)
  238. let skip = page * limit;
  239. that.$set(that, `skip`, skip)
  240. that.search();
  241. uni.hideLoading();
  242. } else that.$set(that, `is_bottom`, true)
  243. },
  244. toScroll(e) {
  245. const that = this;
  246. let up = that.scrollTop;
  247. that.$set(that, `scrollTop`, e.detail.scrollTop);
  248. let num = Math.sign(up - e.detail.scrollTop);
  249. if (num == 1) that.$set(that, `is_bottom`, false);
  250. },
  251. // 清空列表
  252. clearPage() {
  253. const that = this;
  254. that.$set(that, `list`, [])
  255. that.$set(that, `skip`, 0)
  256. that.$set(that, `limit`, 6)
  257. that.$set(that, `page`, 0)
  258. }
  259. }
  260. }
  261. </script>
  262. <style lang="scss" scoped>
  263. .main {
  264. display: flex;
  265. flex-direction: column;
  266. width: 100vw;
  267. height: 100vh;
  268. .one {
  269. display: flex;
  270. justify-content: center;
  271. align-items: center;
  272. padding: 2vw;
  273. .one_1 {
  274. padding: 0 2vw;
  275. width: 85vw;
  276. input {
  277. padding: 2vw;
  278. background-color: var(--f1Color);
  279. font-size: var(--font14Size);
  280. border-radius: 5px;
  281. }
  282. }
  283. }
  284. .two {
  285. position: relative;
  286. flex-grow: 1;
  287. background-color: var(--f9Color);
  288. margin: 2vw 0 0 0;
  289. .pubuBox {
  290. padding: 2vw;
  291. }
  292. .pubuItem {
  293. column-count: 2;
  294. column-gap: 2vw;
  295. }
  296. .list {
  297. box-sizing: border-box;
  298. border-radius: 2vw;
  299. overflow: hidden;
  300. background-color: var(--mainColor);
  301. break-inside: avoid;
  302. /*避免在元素内部插入分页符*/
  303. box-sizing: border-box;
  304. margin-bottom: 2vw;
  305. }
  306. .list image {
  307. width: 100%;
  308. }
  309. .title {
  310. padding: 2vw;
  311. .title_1 {
  312. font-size: var(--font14Size);
  313. line-height: 4vw;
  314. text-overflow: -o-ellipsis-lastline;
  315. overflow: hidden;
  316. text-overflow: ellipsis;
  317. display: -webkit-box;
  318. -webkit-line-clamp: 2;
  319. line-clamp: 2;
  320. -webkit-box-orient: vertical;
  321. min-height: 6vw;
  322. max-height: 20vw;
  323. }
  324. .title_2 {
  325. display: flex;
  326. justify-content: space-between;
  327. font-size: var(--font12Size);
  328. color: var(--f69Color);
  329. padding: 1vw 0;
  330. .right {
  331. display: flex;
  332. align-items: center;
  333. text:first-child {
  334. padding: 0 1vw 0 0;
  335. }
  336. }
  337. }
  338. }
  339. .button {
  340. text-align: center;
  341. margin: 0 0 1vw 0;
  342. .button {
  343. background-color: var(--f3CColor);
  344. color: var(--mainColor);
  345. margin: 0 1vw 0 0;
  346. }
  347. }
  348. }
  349. }
  350. </style>