index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <template>
  2. <view class="page_publish">
  3. <view class="publish_header">
  4. <uni-icons type="back" size="24" color="#333333" @click="goBack"></uni-icons>
  5. <text class="header_title">发布通知</text>
  6. <text class="header_placeholder"></text>
  7. </view>
  8. <scroll-view scroll-y class="publish_content">
  9. <view class="form_item">
  10. <view class="form_row form_row_type">
  11. <text class="form_label">通知类型</text>
  12. <view class="form_content">
  13. <picker mode="selector" :range="typeOptions" :value="typeIndex" @change="handleTypeChange">
  14. <view class="filter_item">
  15. <text class="filter_text" :class="{ placeholder: typeIndex === -1 }">{{
  16. formData.noticeType || '请选择类型' }}</text>
  17. <uni-icons type="down" size="16" color="#999999"></uni-icons>
  18. </view>
  19. </picker>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="form_item">
  24. <view class="form_row form_row_type">
  25. <text class="form_label">通知标题</text>
  26. <view class="form_content">
  27. <input type="text" class="form_input" v-model="formData.title" placeholder="请输入任务名称" />
  28. </view>
  29. </view>
  30. </view>
  31. <view class="form_item">
  32. <view class="form_row">
  33. <text class="form_label">通知内容</text>
  34. <view class="form_content">
  35. <view class="textarea_container">
  36. <textarea class="form_textarea" v-model="formData.content" placeholder="请输入通知内容"
  37. :maxlength="-1"></textarea>
  38. <view class="textarea_actions">
  39. <image src="/static/image/publish/full.png" class="full_icon" mode="aspectFit"></image>
  40. <text class="action_text">全屏编辑</text>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="form_item">
  47. <view class="form_row">
  48. <text class="form_label">发布时间</text>
  49. <view class="form_content">
  50. <custom-radio v-model="publishType" :options="publishOptions" />
  51. <view v-if="publishType === 1" class="time_picker">
  52. <uni-datetime-picker v-model="publishDateTime" type="datetime" :start="startTime"
  53. :end="endTime" return-type="string" />
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="form_item">
  59. <view class="form_row">
  60. <text class="form_label">通知对象</text>
  61. <view class="form_content">
  62. <view class="object_row">
  63. <view class="object_info">
  64. <text class="object_count">按部门</text>
  65. <text class="object_count">已选32人</text>
  66. </view>
  67. <view class="object_action" @click="selectObject">
  68. <text class="action_text">选择通知对象</text>
  69. <text class="action_arrow">></text>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view class="form_item">
  76. <view class="form_row">
  77. <text class="form_label">通知状态</text>
  78. <view class="form_content">
  79. <view class="switch_row">
  80. <view class="switch_container">
  81. <switch :checked="formData.status" color="#2E64FA" @change="onStatusChange" />
  82. </view>
  83. <text class="switch_text">说明:关闭后通知不对通知对象显示</text>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. <view class="form_item">
  89. <view class="form_row">
  90. <text class="form_label">已读记录</text>
  91. <view class="form_content">
  92. <custom-radio v-model="saveRecord" :options="recordOptions" />
  93. <text class="record_tip">说明:已读记录将被清空,重新记录</text>
  94. </view>
  95. </view>
  96. </view>
  97. </scroll-view>
  98. <view class="publish_footer">
  99. <view class="confirm_btn" @click="handleSave">
  100. <text class="btn_text">确定</text>
  101. </view>
  102. </view>
  103. </view>
  104. </template>
  105. <script setup>
  106. import { ref, reactive, onMounted } from 'vue';
  107. import uniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue';
  108. import uniDatetimePicker from '@/uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue';
  109. import overviewApi from '@/reqApi/overview.js';
  110. import CustomRadio from '@/components/customRadio.vue';
  111. const showTypePicker = ref(false);
  112. const publishType = ref(1);
  113. const saveRecord = ref(1);
  114. const typeIndex = ref(-1);
  115. const typeData = ref([]);
  116. const typeOptions = ref([]);
  117. const getCurrentDateTime = () => {
  118. const now = new Date();
  119. const year = now.getFullYear();
  120. const month = String(now.getMonth() + 1).padStart(2, '0');
  121. const day = String(now.getDate()).padStart(2, '0');
  122. const hours = String(now.getHours()).padStart(2, '0');
  123. const minutes = String(now.getMinutes()).padStart(2, '0');
  124. const seconds = String(now.getSeconds()).padStart(2, '0');
  125. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  126. };
  127. const publishDateTime = ref(getCurrentDateTime());
  128. const startTime = ref('2024-01-01 00:00:00');
  129. const endTime = ref('2030-12-31 23:59:59');
  130. const publishOptions = [
  131. { label: '立即发布', value: 0 },
  132. { label: '预约发布', value: 1 }
  133. ];
  134. const recordOptions = [
  135. { label: '保存', value: 0 },
  136. { label: '不保存', value: 1 }
  137. ];
  138. const formData = reactive({
  139. title: '',
  140. noticeType: '',
  141. content: '',
  142. status: true
  143. });
  144. const fetchNoticeTypeList = async () => {
  145. try {
  146. const res = await overviewApi.noticeTypeList();
  147. if (res.data && Array.isArray(res.data)) {
  148. typeData.value = res.data.map(item => ({
  149. id: item.id,
  150. name: item.name
  151. }));
  152. typeOptions.value = typeData.value.map(item => item.name);
  153. }
  154. } catch (error) {
  155. console.error('获取通知类型失败:', error);
  156. }
  157. };
  158. onMounted(() => {
  159. fetchNoticeTypeList();
  160. });
  161. const handleTypeChange = (e) => {
  162. typeIndex.value = e.detail.value;
  163. const selectedItem = typeData.value[typeIndex.value];
  164. if (selectedItem) {
  165. formData.noticeType = selectedItem.name;
  166. }
  167. };
  168. const goBack = () => {
  169. uni.redirectTo({ url: '/pages/notice/overview/index' });
  170. };
  171. const onStatusChange = (e) => {
  172. formData.status = e.detail.value;
  173. };
  174. const selectObject = () => {
  175. uni.showToast({ title: '选择通知对象', icon: 'none' });
  176. };
  177. const handleSave = () => {
  178. if (!formData.title) {
  179. uni.showToast({ title: '请输入通知标题', icon: 'none' });
  180. return;
  181. }
  182. if (!formData.content) {
  183. uni.showToast({ title: '请输入通知内容', icon: 'none' });
  184. return;
  185. }
  186. uni.showToast({ title: '发布成功', icon: 'success' });
  187. };
  188. </script>
  189. <style lang="scss" scoped>
  190. .page_publish {
  191. // min-height: 100vh;
  192. // background-color: #F5F5F5;
  193. display: flex;
  194. flex-direction: column;
  195. }
  196. .publish_header {
  197. position: fixed;
  198. top: 0;
  199. left: 0;
  200. right: 0;
  201. z-index: 100;
  202. display: flex;
  203. align-items: center;
  204. justify-content: space-between;
  205. height: 96rpx;
  206. padding: 0 24rpx;
  207. background-color: #FFFFFF;
  208. border-bottom: 2rpx solid #F3F3F3;
  209. .header_title {
  210. font-weight: 500;
  211. font-size: 32rpx;
  212. color: #333333;
  213. }
  214. .header_placeholder {
  215. width: 48rpx;
  216. }
  217. }
  218. .publish_content {
  219. flex: 1;
  220. box-sizing: border-box;
  221. padding: 120rpx 24rpx 158rpx 24rpx;
  222. }
  223. .form_item {
  224. background-color: #FFFFFF;
  225. border-radius: 8rpx;
  226. padding-bottom: 24rpx;
  227. margin-bottom: 24rpx;
  228. border-bottom: 2rpx solid #F3F3F3;
  229. &:last-child {
  230. border-bottom: none;
  231. }
  232. .form_label {
  233. font-size: 28rpx;
  234. color: #666666;
  235. font-weight: 400;
  236. white-space: nowrap;
  237. flex-shrink: 0;
  238. margin-right: 16rpx;
  239. &::after {
  240. content: ':';
  241. margin-left: 8rpx;
  242. }
  243. }
  244. // 通知类型
  245. .form_row {
  246. display: flex;
  247. align-items: flex-start;
  248. .form_content {
  249. flex: 1;
  250. }
  251. }
  252. .form_row_type {
  253. align-items: center;
  254. .filter_item {
  255. display: flex;
  256. align-items: center;
  257. justify-content: space-between;
  258. padding: 0 16rpx;
  259. height: 72rpx;
  260. line-height: 72rpx;
  261. background-color: #FFFFFF;
  262. border-radius: 8rpx;
  263. width: 240rpx;
  264. border: 2rpx solid #DCDFE6;
  265. .filter_text {
  266. font-size: 28rpx;
  267. color: #333333;
  268. margin-right: 8rpx;
  269. &.placeholder {
  270. color: #909399;
  271. }
  272. }
  273. }
  274. }
  275. .form_input {
  276. font-size: 28rpx;
  277. color: #333333;
  278. padding: 0 24rpx;
  279. background-color: #FFFFFF;
  280. border-radius: 8rpx;
  281. width: 100%;
  282. height: 72rpx;
  283. box-sizing: border-box;
  284. border: 2rpx solid #E9E9E9;
  285. }
  286. .form_select {
  287. display: flex;
  288. align-items: center;
  289. justify-content: space-between;
  290. padding: 16rpx;
  291. background-color: #F5F7FA;
  292. border-radius: 8rpx;
  293. border: 2rpx solid #DCDFE6;
  294. .select_text {
  295. font-size: 28rpx;
  296. color: #333333;
  297. }
  298. .select_right {
  299. .select_arrow {
  300. font-size: 28rpx;
  301. color: #999999;
  302. }
  303. }
  304. }
  305. .textarea_container {
  306. position: relative;
  307. .form_textarea {
  308. width: 100%;
  309. height: 240rpx;
  310. font-size: 28rpx;
  311. color: #333333;
  312. line-height: 1.6;
  313. padding: 14rpx 24rpx 56rpx 24rpx;
  314. background-color: #FFFFFF;
  315. border-radius: 8rpx;
  316. box-sizing: border-box;
  317. border: 2rpx solid #E9E9E9;
  318. }
  319. .textarea_actions {
  320. position: absolute;
  321. bottom: 13rpx;
  322. right: 16rpx;
  323. display: flex;
  324. align-items: center;
  325. gap: 8rpx;
  326. .full_icon {
  327. width: 28rpx;
  328. height: 28rpx;
  329. }
  330. .action_text {
  331. font-weight: 400;
  332. font-size: 28rpx;
  333. color: #2E64FA;
  334. }
  335. }
  336. }
  337. .time_picker {
  338. margin-top: 20rpx;
  339. min-width: 300rpx;
  340. height: 68rpx;
  341. float: right;
  342. :deep(.uni-date-x--border) {
  343. height: 68rpx;
  344. }
  345. :deep(.uni-date-x) {
  346. padding: 0 16rpx;
  347. }
  348. :deep(.uni-date-x--text) {
  349. font-weight: 400;
  350. font-size: 28rpx;
  351. color: #333333;
  352. }
  353. :deep(.uni-date__x-input) {
  354. font-size: 28rpx;
  355. color: #333333;
  356. }
  357. }
  358. .object_row {
  359. display: flex;
  360. align-items: center;
  361. justify-content: space-between;
  362. .object_info {
  363. display: flex;
  364. align-items: center;
  365. gap: 12rpx;
  366. .object_count {
  367. font-size: 28rpx;
  368. color: #2E64FA;
  369. }
  370. }
  371. .object_action {
  372. display: flex;
  373. align-items: center;
  374. gap: 8rpx;
  375. .action_text {
  376. font-size: 28rpx;
  377. color: #2E64FA;
  378. }
  379. .action_arrow {
  380. font-size: 28rpx;
  381. color: #2E64FA;
  382. }
  383. }
  384. }
  385. .object_tip {
  386. font-size: 24rpx;
  387. color: #F56C6C;
  388. margin-top: 12rpx;
  389. display: block;
  390. }
  391. .switch_row {
  392. display: flex;
  393. align-items: center;
  394. // gap: 16rpx;
  395. .switch_container {
  396. transform: scale(0.8);
  397. transform-origin: left center;
  398. }
  399. .switch_text {
  400. font-weight: 400;
  401. font-size: 28rpx;
  402. color: #999999;
  403. }
  404. }
  405. .record_tip {
  406. font-weight: 400;
  407. font-size: 28rpx;
  408. color: #999999;
  409. margin-top: 16rpx;
  410. display: block;
  411. }
  412. }
  413. .publish_footer {
  414. padding: 24rpx;
  415. padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
  416. background-color: #FFFFFF;
  417. .confirm_btn {
  418. width: 702rpx;
  419. height: 90rpx;
  420. background: #2E64FA;
  421. border-radius: 8rpx 8rpx 8rpx 8rpx;
  422. text-align: center;
  423. line-height: 90rpx;
  424. .btn_text {
  425. font-size: 32rpx;
  426. font-weight: 500;
  427. color: #FFFFFF;
  428. }
  429. }
  430. }
  431. </style>