notice-header.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <view class="notice_header" :style="{ paddingTop: statusBarHeight + 'rpx' }">
  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 && mode === 'notice'" class="filter_bar">
  17. <picker mode="selector" :range="typeOptions" :value="typeIndex" @change="handleTypeChange">
  18. <view class="filter_item">
  19. <text class="filter_text">{{ typeOptions[typeIndex] }}</text>
  20. <uni-icons type="down" size="16" color="#999999"></uni-icons>
  21. </view>
  22. </picker>
  23. <picker mode="selector" :range="timeOptions" :value="timeIndex" @change="handleTimeChange">
  24. <view class="filter_item">
  25. <text class="filter_text">{{ timeOptions[timeIndex] }}</text>
  26. <uni-icons type="down" size="16" color="#999999"></uni-icons>
  27. </view>
  28. </picker>
  29. </view>
  30. <!-- 通知模式标签栏 -->
  31. <view v-if="showTabs && mode === 'notice'" class="tabs_bar">
  32. <text v-for="(tab, idx) in tabs" :key="idx" class="tab_item" :class="{ active: activeTabIndex === idx }" @click="handleTabChange(idx)">{{ tab }}</text>
  33. </view>
  34. <!-- 任务总览模式过滤栏 -->
  35. <view v-if="showFilter && mode === 'taskOverview'" class="filter_bar task_overview_filter">
  36. <picker mode="selector" class="picker_wide" :range="academicYearOptions" :value="academicYearIndex" @change="handleAcademicYearChange">
  37. <view class="filter_item">
  38. <text class="filter_text">{{ academicYearOptions[academicYearIndex] }}</text>
  39. <uni-icons type="down" size="16" color="#999999"></uni-icons>
  40. </view>
  41. </picker>
  42. <picker mode="selector" class="picker_narrow" :range="categoryOptions" :value="categoryIndex" @change="handleCategoryChange">
  43. <view class="filter_item">
  44. <text class="filter_text">{{ categoryOptions[categoryIndex] }}</text>
  45. <uni-icons type="down" size="16" color="#999999"></uni-icons>
  46. </view>
  47. </picker>
  48. <picker mode="selector" class="picker_narrow" :range="materialTypeOptions" :value="materialTypeIndex" @change="handleMaterialTypeChange">
  49. <view class="filter_item">
  50. <text class="filter_text">{{ materialTypeOptions[materialTypeIndex] }}</text>
  51. <uni-icons type="down" size="16" color="#999999"></uni-icons>
  52. </view>
  53. </picker>
  54. </view>
  55. <!-- 任务总览模式标签栏 -->
  56. <view v-if="(showTabs || showCreateBtn) && mode === 'taskOverview'" class="tabs_bar task_overview_tabs">
  57. <text v-for="(tab, idx) in tabs" :key="idx" class="tab_item" :class="{ active: activeTabIndex === idx }" @click="handleTabChange(idx)">{{ tab }}</text>
  58. <view v-if="showCreateBtn" class="create_btn" @click="handleCreate">
  59. <image src="/static/image/workspace/add.png" class="add_icon" mode="aspectFit"></image>
  60. <text class="create_text">新建</text>
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. <script setup>
  66. import { ref, onMounted, computed } from 'vue';
  67. import uniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue';
  68. import overviewApi from '@/reqApi/overview.js';
  69. import { useSafeArea } from '@/common/safeArea';
  70. const { statusBarHeight, initSafeArea } = useSafeArea();
  71. const typeIndex = ref(0);
  72. const timeIndex = ref(0);
  73. const typeData = ref([{ id: '0', name: '全部类型' }]);
  74. const typeOptions = ref(['全部类型']);
  75. const searchWord = ref('');
  76. const academicYearIndex = ref(0);
  77. const categoryIndex = ref(0);
  78. const materialTypeIndex = ref(0);
  79. const props = defineProps({
  80. title: {
  81. type: String,
  82. default: ''
  83. },
  84. mode: {
  85. type: String,
  86. default: 'notice',
  87. validator: (value) => ['notice', 'taskOverview'].includes(value)
  88. },
  89. showSearch: {
  90. type: Boolean,
  91. default: false
  92. },
  93. showSave: {
  94. type: Boolean,
  95. default: false
  96. },
  97. showFilter: {
  98. type: Boolean,
  99. default: false
  100. },
  101. timeOptions: {
  102. type: Array,
  103. default: () => ['全部时间', '最近3天', '最近7天', '最近1月', '最近3月']
  104. },
  105. academicYearOptions: {
  106. type: Array,
  107. default: () => ['2025-2026学年', '2024-2025学年', '2023-2024学年']
  108. },
  109. categoryOptions: {
  110. type: Array,
  111. default: () => ['全部分类', '日常教学', '考试测评', '教研活动']
  112. },
  113. materialTypeOptions: {
  114. type: Array,
  115. default: () => ['全部类目', '教案', '课件', '试卷', '作业']
  116. },
  117. showTabs: {
  118. type: Boolean,
  119. default: false
  120. },
  121. showCreateBtn: {
  122. type: Boolean,
  123. default: false
  124. },
  125. tabs: {
  126. type: Array,
  127. default: () => ['全部', '待发布', '已发布', '已关闭']
  128. },
  129. activeTab: {
  130. type: Number,
  131. default: -1
  132. },
  133. tabMode: {
  134. type: String,
  135. default: 'status',
  136. validator: (value) => ['status', 'index'].includes(value)
  137. }
  138. });
  139. const activeTabIndex = computed(() => {
  140. if (props.tabMode === 'index') {
  141. return props.activeTab;
  142. }
  143. const statusMap = [-1, 0, 1, 2];
  144. return statusMap.indexOf(props.activeTab);
  145. });
  146. const emit = defineEmits([
  147. 'save', 'tabChange', 'typeChange', 'timeChange', 'searchChange',
  148. 'academicYearChange', 'categoryChange', 'materialTypeChange', 'create'
  149. ]);
  150. const fetchNoticeTypeList = async () => {
  151. try {
  152. const res = await overviewApi.noticeTypeList();
  153. if (res.data && Array.isArray(res.data)) {
  154. const types = res.data.map(item => ({
  155. id: item.id,
  156. name: item.name
  157. }));
  158. typeData.value = [{ id: '0', name: '全部类型' }, ...types];
  159. typeOptions.value = ['全部类型', ...types.map(item => item.name)];
  160. }
  161. } catch (error) {
  162. console.error('获取通知类型失败:', error);
  163. }
  164. };
  165. onMounted(() => {
  166. initSafeArea();
  167. if (props.mode === 'notice') {
  168. fetchNoticeTypeList();
  169. }
  170. });
  171. const handleTabChange = (idx) => {
  172. if (props.tabMode === 'index') {
  173. emit('tabChange', idx);
  174. } else {
  175. const statusMap = [-1, 0, 1, 2];
  176. emit('tabChange', statusMap[idx]);
  177. }
  178. };
  179. const handleTypeChange = (e) => {
  180. typeIndex.value = e.detail.value;
  181. const selectedItem = typeData.value[typeIndex.value];
  182. emit('typeChange', selectedItem.id);
  183. };
  184. const handleTimeChange = (e) => {
  185. timeIndex.value = e.detail.value;
  186. emit('timeChange', timeIndex.value);
  187. };
  188. const handleAcademicYearChange = (e) => {
  189. academicYearIndex.value = e.detail.value;
  190. emit('academicYearChange', academicYearIndex.value);
  191. };
  192. const handleCategoryChange = (e) => {
  193. categoryIndex.value = e.detail.value;
  194. emit('categoryChange', categoryIndex.value);
  195. };
  196. const handleMaterialTypeChange = (e) => {
  197. materialTypeIndex.value = e.detail.value;
  198. emit('materialTypeChange', materialTypeIndex.value);
  199. };
  200. const goBack = () => {
  201. uni.redirectTo({
  202. url: '/pages/workspace/index'
  203. });
  204. };
  205. const handleSave = () => {
  206. emit('save');
  207. };
  208. const handleSearchInput = () => {
  209. emit('searchChange', searchWord.value);
  210. };
  211. const handleCreate = () => {
  212. emit('create');
  213. };
  214. </script>
  215. <style lang="scss" scoped>
  216. .notice_header {
  217. position: fixed;
  218. top: 0;
  219. left: 0;
  220. right: 0;
  221. display: flex;
  222. flex-direction: column;
  223. background-color: #FFFFFF;
  224. z-index: 999;
  225. .header_top {
  226. display: flex;
  227. align-items: center;
  228. justify-content: space-between;
  229. padding: 24rpx;
  230. .header_left {
  231. display: flex;
  232. align-items: center;
  233. .header_title {
  234. font-weight: 600;
  235. font-size: 44rpx;
  236. color: #333333;
  237. margin-left: 24rpx;
  238. }
  239. }
  240. .search_box {
  241. display: flex;
  242. align-items: center;
  243. background-color: #fff;
  244. border-radius: 8rpx;
  245. padding: 14rpx 24rpx;
  246. width: 265rpx;
  247. border: 2rpx solid #DCDFE6;
  248. .search_icon {
  249. width: 32rpx;
  250. height: 32rpx;
  251. margin-right: 8rpx;
  252. }
  253. .search_input {
  254. flex: 1;
  255. font-size: 24rpx;
  256. color: #333333;
  257. margin-left: 8rpx;
  258. }
  259. .search_placeholder {
  260. color: #999999;
  261. }
  262. }
  263. .save_btn {
  264. font-size: 28rpx;
  265. color: #2E64FA;
  266. font-weight: 500;
  267. }
  268. }
  269. .filter_bar {
  270. display: flex;
  271. gap: 32rpx;
  272. padding: 20rpx 24rpx;
  273. background-color: #FFFFFF;
  274. border-top: 1rpx solid #F0F0F0;
  275. .filter_item {
  276. display: flex;
  277. align-items: center;
  278. justify-content: space-between;
  279. padding: 20rpx 16rpx;
  280. background-color: #FFFFFF;
  281. border-radius: 8rpx;
  282. min-width: 240rpx;
  283. border: 2rpx solid #DCDFE6;
  284. .filter_text {
  285. font-size: 28rpx;
  286. color: #333333;
  287. margin-right: 8rpx;
  288. }
  289. }
  290. }
  291. .task_overview_filter {
  292. gap: 16rpx;
  293. .picker_wide {
  294. flex: 1.2;
  295. }
  296. .picker_narrow {
  297. flex: 1;
  298. }
  299. .filter_item {
  300. width: 100%;
  301. min-width: 0;
  302. padding: 16rpx 12rpx;
  303. box-sizing: border-box;
  304. .filter_text {
  305. font-size: 24rpx;
  306. overflow: hidden;
  307. text-overflow: ellipsis;
  308. white-space: nowrap;
  309. }
  310. }
  311. }
  312. .tabs_bar {
  313. display: flex;
  314. height: 56rpx;
  315. padding: 4rpx 24rpx 12rpx 24rpx;
  316. .tab_item {
  317. font-size: 32rpx;
  318. color: #999999;
  319. font-weight: 400;
  320. position: relative;
  321. margin-right: 48rpx;
  322. &.active {
  323. color: #2E64FA;
  324. font-weight: 500;
  325. &::after {
  326. content: '';
  327. position: absolute;
  328. bottom: 0rpx;
  329. left: 50%;
  330. transform: translateX(-50%);
  331. width: 100%;
  332. height: 4rpx;
  333. background-color: #2E64FA;
  334. }
  335. }
  336. }
  337. }
  338. .task_overview_tabs {
  339. justify-content: flex-start;
  340. align-items: center;
  341. height: 72rpx;
  342. .tab_item {
  343. margin-right: 48rpx;
  344. &.active {
  345. &::after {
  346. bottom: -8rpx;
  347. }
  348. }
  349. }
  350. .create_btn {
  351. margin-left: auto;
  352. background-color: #2E64FA;
  353. border-radius: 8rpx;
  354. width: 148rpx;
  355. height: 72rpx;
  356. display: flex;
  357. align-items: center;
  358. justify-content: center;
  359. gap: 8rpx;
  360. .add_icon {
  361. width: 32rpx;
  362. height: 32rpx;
  363. }
  364. .create_text {
  365. color: #FFFFFF;
  366. font-size: 28rpx;
  367. font-weight: 500;
  368. }
  369. }
  370. }
  371. }
  372. </style>