notice-header.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view class="notice_header">
  3. <!-- 顶部栏 -->
  4. <view class="header_top">
  5. <view class="header_left">
  6. <uni-icons type="back" size="24" color="#333333" @click="goBack"></uni-icons>
  7. <text class="header_title">{{ title }}</text>
  8. </view>
  9. <view v-if="showSearch" class="search_box">
  10. <image src="/static/image/overview/search.png" class="search_icon" ></image>
  11. <input type="text" class="search_input" placeholder="请输入关键字搜索" placeholder-class="search_placeholder" v-model="searchWord" @input="handleSearchInput" />
  12. </view>
  13. <text v-else-if="showSave" class="save_btn" @click="handleSave">保存</text>
  14. </view>
  15. <!-- 过滤栏 -->
  16. <view v-if="showFilter" class="filter_bar">
  17. <!-- 通知类型筛选 -->
  18. <picker mode="selector" :range="typeOptions" :value="typeIndex" @change="handleTypeChange">
  19. <view class="filter_item">
  20. <text class="filter_text">{{ typeOptions[typeIndex] }}</text>
  21. <uni-icons type="down" size="16" color="#999999"></uni-icons>
  22. </view>
  23. </picker>
  24. <!-- 时间筛选 -->
  25. <picker mode="selector" :range="timeOptions" :value="timeIndex" @change="handleTimeChange">
  26. <view class="filter_item">
  27. <text class="filter_text">{{ timeOptions[timeIndex] }}</text>
  28. <uni-icons type="down" size="16" color="#999999"></uni-icons>
  29. </view>
  30. </picker>
  31. </view>
  32. <!-- 标签栏 -->
  33. <view v-if="showTabs" class="tabs_bar">
  34. <text v-for="(tab, idx) in tabs" :key="idx" class="tab_item" :class="{ active: activeTabIndex === idx }" @click="handleTabChange(idx)">{{ tab }}</text>
  35. </view>
  36. </view>
  37. </template>
  38. <script setup>
  39. import { ref, onMounted, computed } from 'vue';
  40. import uniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue';
  41. import overviewApi from '@/reqApi/overview.js';
  42. const typeIndex = ref(0);
  43. const timeIndex = ref(0);
  44. const typeData = ref([{ id: '0', name: '全部类型' }]);
  45. const typeOptions = ref(['全部类型']);
  46. const searchWord = ref('');
  47. const props = defineProps({
  48. title: {
  49. type: String,
  50. default: ''
  51. },
  52. showSearch: {
  53. type: Boolean,
  54. default: false
  55. },
  56. showSave: {
  57. type: Boolean,
  58. default: false
  59. },
  60. showFilter: {
  61. type: Boolean,
  62. default: false
  63. },
  64. timeOptions: {
  65. type: Array,
  66. default: () => ['全部时间', '最近3天', '最近7天', '最近1月', '最近3月']
  67. },
  68. showTabs: {
  69. type: Boolean,
  70. default: false
  71. },
  72. tabs: {
  73. type: Array,
  74. default: () => ['全部', '待发布', '已发布', '已关闭']
  75. },
  76. activeTab: {
  77. type: Number,
  78. default: -1
  79. }
  80. });
  81. const activeTabIndex = computed(() => {
  82. const statusMap = [-1, 0, 1, 2];
  83. return statusMap.indexOf(props.activeTab);
  84. });
  85. const emit = defineEmits(['save', 'tabChange', 'typeChange', 'timeChange', 'searchChange']);
  86. const fetchNoticeTypeList = async () => {
  87. try {
  88. const res = await overviewApi.noticeTypeList();
  89. if (res.data && Array.isArray(res.data)) {
  90. const types = res.data.map(item => ({
  91. id: item.id,
  92. name: item.name
  93. }));
  94. typeData.value = [{ id: '0', name: '全部类型' }, ...types];
  95. typeOptions.value = ['全部类型', ...types.map(item => item.name)];
  96. }
  97. } catch (error) {
  98. console.error('获取通知类型失败:', error);
  99. }
  100. };
  101. onMounted(() => {
  102. fetchNoticeTypeList();
  103. });
  104. const handleTabChange = (idx) => {
  105. const statusMap = [-1, 0, 1, 2];
  106. emit('tabChange', statusMap[idx]);
  107. };
  108. const handleTypeChange = (e) => {
  109. typeIndex.value = e.detail.value;
  110. const selectedItem = typeData.value[typeIndex.value];
  111. emit('typeChange', selectedItem.id);
  112. };
  113. const handleTimeChange = (e) => {
  114. timeIndex.value = e.detail.value;
  115. emit('timeChange', timeIndex.value);
  116. };
  117. const goBack = () => {
  118. uni.switchTab({
  119. url: '/pages/workspace/index'
  120. });
  121. };
  122. const handleSave = () => {
  123. emit('save');
  124. };
  125. const handleSearchInput = () => {
  126. emit('searchChange', searchWord.value);
  127. };
  128. </script>
  129. <style lang="scss" scoped>
  130. .notice_header {
  131. position: fixed;
  132. top: 0;
  133. left: 0;
  134. right: 0;
  135. display: flex;
  136. flex-direction: column;
  137. background-color: #FFFFFF;
  138. z-index: 999;
  139. // border-bottom: 2rpx solid #EBEEF5;
  140. .header_top {
  141. display: flex;
  142. align-items: center;
  143. justify-content: space-between;
  144. padding: 24rpx;
  145. .header_left {
  146. display: flex;
  147. align-items: center;
  148. .header_title {
  149. font-weight: 600;
  150. font-size: 44rpx;
  151. color: #333333;
  152. margin-left: 24rpx;
  153. }
  154. }
  155. .search_box {
  156. display: flex;
  157. align-items: center;
  158. background-color: #fff;
  159. border-radius: 8rpx;
  160. padding: 14rpx 24rpx;
  161. width: 265rpx;
  162. border: 2rpx solid #DCDFE6;
  163. .search_icon {
  164. width: 32rpx;
  165. height: 32rpx;
  166. margin-right: 8rpx;
  167. }
  168. .search_input {
  169. flex: 1;
  170. font-size: 24rpx;
  171. color: #333333;
  172. margin-left: 8rpx;
  173. }
  174. .search_placeholder {
  175. color: #999999;
  176. }
  177. }
  178. .save_btn {
  179. font-size: 28rpx;
  180. color: #2E64FA;
  181. font-weight: 500;
  182. }
  183. }
  184. .filter_bar {
  185. display: flex;
  186. gap: 32rpx;
  187. padding: 20rpx 24rpx;
  188. background-color: #FFFFFF;
  189. border-top: 1rpx solid #F0F0F0;
  190. .filter_item {
  191. display: flex;
  192. align-items: center;
  193. justify-content: space-between;
  194. padding: 20rpx 16rpx;
  195. background-color: #FFFFFF;
  196. border-radius: 8rpx;
  197. min-width: 240rpx;
  198. // height: 72rpx;
  199. border: 2rpx solid #DCDFE6;
  200. .filter_text {
  201. font-size: 28rpx;
  202. color: #333333;
  203. margin-right: 8rpx;
  204. }
  205. }
  206. }
  207. .tabs_bar {
  208. display: flex;
  209. padding-top: 4rpx;
  210. height: 56rpx;
  211. padding-left: 24rpx;
  212. .tab_item {
  213. font-size: 32rpx;
  214. color: #999999;
  215. font-weight: 400;
  216. position: relative;
  217. margin-right: 48rpx;
  218. &.active {
  219. color: #2E64FA;
  220. font-weight: 500;
  221. &::after {
  222. content: '';
  223. position: absolute;
  224. bottom: 0rpx;
  225. left: 50%;
  226. transform: translateX(-50%);
  227. width: 48rpx;
  228. height: 4rpx;
  229. background-color: #2E64FA;
  230. // border-radius: 2rpx;
  231. }
  232. }
  233. }
  234. }
  235. }
  236. </style>