notice-header.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. tabMode: {
  81. type: String,
  82. default: 'status',
  83. validator: (value) => ['status', 'index'].includes(value)
  84. }
  85. });
  86. const activeTabIndex = computed(() => {
  87. if (props.tabMode === 'index') {
  88. return props.activeTab;
  89. }
  90. const statusMap = [-1, 0, 1, 2];
  91. return statusMap.indexOf(props.activeTab);
  92. });
  93. const emit = defineEmits(['save', 'tabChange', 'typeChange', 'timeChange', 'searchChange']);
  94. const fetchNoticeTypeList = async () => {
  95. try {
  96. const res = await overviewApi.noticeTypeList();
  97. if (res.data && Array.isArray(res.data)) {
  98. const types = res.data.map(item => ({
  99. id: item.id,
  100. name: item.name
  101. }));
  102. typeData.value = [{ id: '0', name: '全部类型' }, ...types];
  103. typeOptions.value = ['全部类型', ...types.map(item => item.name)];
  104. }
  105. } catch (error) {
  106. console.error('获取通知类型失败:', error);
  107. }
  108. };
  109. onMounted(() => {
  110. fetchNoticeTypeList();
  111. });
  112. const handleTabChange = (idx) => {
  113. if (props.tabMode === 'index') {
  114. emit('tabChange', idx);
  115. } else {
  116. const statusMap = [-1, 0, 1, 2];
  117. emit('tabChange', statusMap[idx]);
  118. }
  119. };
  120. const handleTypeChange = (e) => {
  121. typeIndex.value = e.detail.value;
  122. const selectedItem = typeData.value[typeIndex.value];
  123. emit('typeChange', selectedItem.id);
  124. };
  125. const handleTimeChange = (e) => {
  126. timeIndex.value = e.detail.value;
  127. emit('timeChange', timeIndex.value);
  128. };
  129. const goBack = () => {
  130. uni.switchTab({
  131. url: '/pages/workspace/index'
  132. });
  133. };
  134. const handleSave = () => {
  135. emit('save');
  136. };
  137. const handleSearchInput = () => {
  138. emit('searchChange', searchWord.value);
  139. };
  140. </script>
  141. <style lang="scss" scoped>
  142. .notice_header {
  143. position: fixed;
  144. top: 0;
  145. left: 0;
  146. right: 0;
  147. display: flex;
  148. flex-direction: column;
  149. background-color: #FFFFFF;
  150. z-index: 999;
  151. padding-top: env(safe-area-inset-top);
  152. // border-bottom: 2rpx solid #EBEEF5;
  153. .header_top {
  154. display: flex;
  155. align-items: center;
  156. justify-content: space-between;
  157. padding: 24rpx;
  158. .header_left {
  159. display: flex;
  160. align-items: center;
  161. .header_title {
  162. font-weight: 600;
  163. font-size: 44rpx;
  164. color: #333333;
  165. margin-left: 24rpx;
  166. }
  167. }
  168. .search_box {
  169. display: flex;
  170. align-items: center;
  171. background-color: #fff;
  172. border-radius: 8rpx;
  173. padding: 14rpx 24rpx;
  174. width: 265rpx;
  175. border: 2rpx solid #DCDFE6;
  176. .search_icon {
  177. width: 32rpx;
  178. height: 32rpx;
  179. margin-right: 8rpx;
  180. }
  181. .search_input {
  182. flex: 1;
  183. font-size: 24rpx;
  184. color: #333333;
  185. margin-left: 8rpx;
  186. }
  187. .search_placeholder {
  188. color: #999999;
  189. }
  190. }
  191. .save_btn {
  192. font-size: 28rpx;
  193. color: #2E64FA;
  194. font-weight: 500;
  195. }
  196. }
  197. .filter_bar {
  198. display: flex;
  199. gap: 32rpx;
  200. padding: 20rpx 24rpx;
  201. background-color: #FFFFFF;
  202. border-top: 1rpx solid #F0F0F0;
  203. .filter_item {
  204. display: flex;
  205. align-items: center;
  206. justify-content: space-between;
  207. padding: 20rpx 16rpx;
  208. background-color: #FFFFFF;
  209. border-radius: 8rpx;
  210. min-width: 240rpx;
  211. // height: 72rpx;
  212. border: 2rpx solid #DCDFE6;
  213. .filter_text {
  214. font-size: 28rpx;
  215. color: #333333;
  216. margin-right: 8rpx;
  217. }
  218. }
  219. }
  220. .tabs_bar {
  221. display: flex;
  222. height: 56rpx;
  223. padding:4rpx 24rpx 24rpx 24rpx;
  224. .tab_item {
  225. font-size: 32rpx;
  226. color: #999999;
  227. font-weight: 400;
  228. position: relative;
  229. margin-right: 48rpx;
  230. &.active {
  231. color: #2E64FA;
  232. font-weight: 500;
  233. &::after {
  234. content: '';
  235. position: absolute;
  236. bottom: 0rpx;
  237. left: 50%;
  238. transform: translateX(-50%);
  239. width: 48rpx;
  240. height: 4rpx;
  241. background-color: #2E64FA;
  242. // border-radius: 2rpx;
  243. }
  244. }
  245. }
  246. }
  247. }
  248. </style>