index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. const loading = ref(false);
  97. const finished = ref(false);
  98. const refreshing = ref(false);
  99. const onRefresh = () => {
  100. queryDailyNotifyByPage(true);
  101. };
  102. const onLoad = () => {
  103. loading.value = true;
  104. pageData.value.pageNo = pageData.value.pageNo + 1
  105. queryDailyNotifyByPage();
  106. };
  107. const pageData = ref<{
  108. pageNo: number
  109. pageSize: number
  110. total?: number
  111. }>({
  112. pageNo: 0,
  113. pageSize: 8,
  114. total: 0
  115. })
  116. /**
  117. * 所有数据
  118. */
  119. const noticeLists = ref<any[]>([]);
  120. const queryDailyNotifyByPage = (isPull = false) => {
  121. if (isPull) {
  122. pageData.value.pageNo = 1
  123. refreshing.value = true;
  124. finished.value = false;
  125. }
  126. const sendData = {
  127. type: 3,
  128. readType: 2,
  129. ...pageData.value
  130. }
  131. if(pageData.value.pageNo === 1) noticeLists.value = []
  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. } else {
  141. loading.value = false
  142. }
  143. /** 用来解决tab切换时,容器高度发生变化自动触发loading事件 */
  144. const time = setTimeout(() => {
  145. loading.value = false;
  146. clearTimeout(time);
  147. }, 800);
  148. if (resultData.total === noticeLists.value.length) {
  149. finished.value = true;
  150. }
  151. } else {
  152. loading.value = false;
  153. finished.value = true;
  154. }
  155. });
  156. }
  157. /**
  158. * 数据列表分组
  159. */
  160. const listMap = ref<any>({})
  161. const queryDailyNotifyGroup = () => {
  162. const sendData = {
  163. type: 3,
  164. readType: 2
  165. }
  166. reqest.post('/admin-api/adm/noticeAndLearn/query/group', sendData).then((result: any) => {
  167. const resultData = result.data;
  168. if (resultData) {
  169. listMap.value = resultData;
  170. }
  171. });
  172. }
  173. const initDailyNotifyData = () => {
  174. pageData.value.pageNo = 0
  175. loading.value = false
  176. finished.value = false
  177. refreshing.value = false
  178. queryDailyNotifyTotal()
  179. queryDailyNotifyGroup()
  180. }
  181. initDailyNotifyData()
  182. const router = useRouter()
  183. const clickHandler = (item: any) => {
  184. router.push({
  185. path: currentTab.value === '3' ? '/dailyNotifyPublish' : '/dailyNotifyDetail',
  186. query: {
  187. id: item['id']
  188. }
  189. });
  190. }
  191. const onDeleteHandle = (item: any) => {
  192. reqest.get(`/admin-api/adm/noticeAndLearn/delete?id=${item.id}`).then((result: any) => {
  193. if(result.data){
  194. showNotify({
  195. type: 'primary',
  196. message: '删除成功',
  197. duration: 800,
  198. position: 'top',
  199. onOpened() {
  200. initDailyNotifyData();
  201. }
  202. });
  203. }
  204. });
  205. }
  206. </script>
  207. <style lang="scss" scoped>
  208. @import "./index.scss";
  209. </style>