index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <div class="dailyNotify_box">
  3. <van-sticky>
  4. <div class="filter_tags">
  5. <span v-for="(item,index) in tabs" :key="index" :class="{active: currentTab === item['index']}" @click="switchTabHandle(item)">{{item['title']}}({{item['num']}})</span>
  6. </div>
  7. </van-sticky>
  8. <div class="handlecenter_card_box">
  9. <template v-if="currentTab === '2'">
  10. <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
  11. <van-list
  12. v-model:loading="loading"
  13. :finished="finished"
  14. finished-text="没有更多了"
  15. @load="onLoad"
  16. >
  17. <div v-for="(item,index) in noticeLists" :key="index" @click="clickHandler(item, false)" :class="{ handlecenter_card: true, handlecenter_card_0: index === 0 }">
  18. <img src="../../assets/images/mrsd_icon.png" />
  19. <div class="box">
  20. <div class="title">{{(item['content']??'暂无标题').substring(0, 50)}}<span class="news" v-if="item['isToday']"><img src="../../assets/images/news_icon.png" /></span></div>
  21. <div class="tip">
  22. <span>{{ item['nickname'] }}</span>
  23. <span>{{item['createTime']}}</span>
  24. </div>
  25. </div>
  26. </div>
  27. </van-list>
  28. </van-pull-refresh>
  29. </template>
  30. <template v-else>
  31. <van-swipe-cell v-for="(item,index) in listMap[currentTab]" :key="index">
  32. <div :class="{ handlecenter_card: true, handlecenter_card_1: index === 0 }" @click="clickHandler(item, false)">
  33. <img src="../../assets/images/mrsd_icon.png" />
  34. <div class="box">
  35. <div class="title">{{(item['content']??'暂无标题').substring(0, 50)}}<span class="news" v-if="currentTab != '1' && item['isToday']"><img src="../../assets/images/news_icon.png" /></span></div>
  36. <div class="tip">
  37. <span>{{ item['nickname'] }}</span>
  38. <span>{{item['createTime']}}</span>
  39. </div>
  40. </div>
  41. </div>
  42. <template v-if="currentTab === '3'" #right>
  43. <van-button square type="danger" @click="onDeleteHandle(item)" text="删除" />
  44. </template>
  45. </van-swipe-cell>
  46. </template>
  47. </div>
  48. </div>
  49. </template>
  50. <script setup lang="ts">
  51. import { showNotify } from 'vant';
  52. import reqest from "@/utils/request";
  53. defineOptions({
  54. name: 'Notice'
  55. })
  56. interface TabType {
  57. title: string,
  58. index: string,
  59. num: number
  60. }
  61. const currentTab = ref<string>("0")
  62. const switchTabHandle = (item: TabType)=>{
  63. currentTab.value = item.index
  64. }
  65. const tabs = ref<TabType[]>([
  66. {
  67. title: '近三日',
  68. index: "0",
  69. num: 0
  70. },{
  71. title: '今日',
  72. index: "1",
  73. num: 0
  74. },{
  75. title: '所有',
  76. index: "2",
  77. num: 0
  78. },{
  79. title: '我的',
  80. index: "3",
  81. num: 0
  82. }
  83. ])
  84. const queryDailyNotifyTotal = () => {
  85. const sendData = {
  86. type: 3,
  87. readType: 2
  88. }
  89. reqest.post('/admin-api/adm/noticeAndLearn/query/total', sendData).then((result: any) => {
  90. const resultData = result.data;
  91. if (resultData) {
  92. tabs.value = resultData;
  93. }
  94. });
  95. }
  96. queryDailyNotifyTotal()
  97. const loading = ref(false);
  98. const finished = ref(false);
  99. const refreshing = ref(false);
  100. const onRefresh = () => {
  101. queryDailyNotifyByPage(true);
  102. };
  103. const onLoad = () => {
  104. loading.value = true;
  105. pageData.value.pageNo = pageData.value.pageNo + 1
  106. queryDailyNotifyByPage();
  107. };
  108. const pageData = ref<{
  109. pageNo: number
  110. pageSize: number
  111. total?: number
  112. }>({
  113. pageNo: 0,
  114. pageSize: 10,
  115. total: 0
  116. })
  117. /**
  118. * 所有数据
  119. */
  120. const noticeLists = ref<any[]>([]);
  121. const queryDailyNotifyByPage = (isPull = false) => {
  122. if (isPull) {
  123. pageData.value.pageNo = 1
  124. refreshing.value = true;
  125. finished.value = false;
  126. }
  127. const sendData = {
  128. type: 3,
  129. readType: 2,
  130. ...pageData.value
  131. }
  132. reqest.post('/admin-api/adm/noticeAndLearn/query/page', sendData).then((result: any) => {
  133. const resultData = result.data;
  134. if (resultData) {
  135. if (resultData && resultData.list) {
  136. isPull ? noticeLists.value = resultData.list : noticeLists.value?.push(...resultData.list)
  137. }
  138. if (isPull) {
  139. refreshing.value = false
  140. }
  141. /** 用来解决tab切换时,容器高度发生变化自动触发loading事件 */
  142. const time = setTimeout(() => {
  143. loading.value = false;
  144. clearTimeout(time);
  145. }, 800);
  146. if (resultData.total === noticeLists.value.length) {
  147. finished.value = true;
  148. }
  149. } else {
  150. loading.value = false;
  151. finished.value = true;
  152. }
  153. });
  154. }
  155. /**
  156. * 数据列表分组
  157. */
  158. const listMap = ref<any>({})
  159. const queryDailyNotifyGroup = () => {
  160. const sendData = {
  161. type: 3,
  162. readType: 2
  163. }
  164. reqest.post('/admin-api/adm/noticeAndLearn/query/group', sendData).then((result: any) => {
  165. const resultData = result.data;
  166. if (resultData) {
  167. listMap.value = resultData;
  168. }
  169. });
  170. }
  171. queryDailyNotifyGroup();
  172. const router = useRouter()
  173. const clickHandler = (item: any) => {
  174. router.push({
  175. path: currentTab.value === '3' ? '/dailyNotifyPublish' : '/dailyNotifyDetail',
  176. query: {
  177. id: item['id']
  178. }
  179. });
  180. }
  181. const onDeleteHandle = (item: any) => {
  182. reqest.get(`/admin-api/adm/noticeAndLearn/delete?id=${item.id}`).then((result: any) => {
  183. if(result.data){
  184. showNotify({
  185. type: 'primary',
  186. message: '删除成功',
  187. duration: 2000,
  188. position: 'top',
  189. onOpened() {
  190. queryDailyNotifyGroup();
  191. }
  192. });
  193. }
  194. });
  195. }
  196. </script>
  197. <style lang="scss" scoped>
  198. @import "./index.scss";
  199. </style>