add-information.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import OHeader from '@/components/o-header'
  2. import OSticky from '@/components/o-sticky'
  3. import OUpload from '@/components/o-upload'
  4. import request from '@/helpers/request'
  5. import { verifyUrl } from '@/helpers/toolsValidate'
  6. import router from '@/router'
  7. import { state } from '@/state'
  8. import { Button, Field, Form, showNotify, showToast } from 'vant'
  9. import { defineComponent, onMounted, reactive, ref, watch } from 'vue'
  10. import { useRoute, useRouter } from 'vue-router'
  11. import styles from './add-information.module.less'
  12. export default defineComponent({
  13. name: 'add-information',
  14. props: {
  15. selectType: {
  16. type: String,
  17. default: 'add'
  18. },
  19. selectItem: {
  20. type: Object,
  21. default: {}
  22. }
  23. },
  24. emits: ['close', 'getList'],
  25. setup(props, { emit }) {
  26. const route = useRoute()
  27. const router = useRouter()
  28. const header = ref('添加资讯')
  29. const forms = reactive({
  30. type: 'HOT_CONSULTATION',
  31. clientType: 'SCHOOL',
  32. coverImage: null,
  33. title: null,
  34. linkUrl: '',
  35. linkType: 'OUT',
  36. status: true,
  37. summary: null
  38. })
  39. const onSubmit = async () => {
  40. if (!forms.coverImage) {
  41. showToast('请上传封面图片')
  42. return
  43. } else if (!forms.title) {
  44. showToast('请输入资讯标题')
  45. return
  46. } else if (!forms.summary) {
  47. showToast('请输入内容简介')
  48. return
  49. } else if (!forms.linkUrl) {
  50. showToast('请输入链接')
  51. return
  52. } else if (!verifyUrl(forms.linkUrl)) {
  53. showToast('链接输入有误')
  54. return
  55. }
  56. try {
  57. if (!route.query.id) {
  58. await request.post('/api-school/sysNewsInformation/save', {
  59. data: {
  60. ...forms
  61. }
  62. })
  63. // showNotify({ type: 'primary', message: '添加成功' })
  64. } else {
  65. await request.post('/api-school/sysNewsInformation/update', {
  66. data: {
  67. ...forms,
  68. id: route.query.id
  69. }
  70. })
  71. // showNotify({ type: 'primary', message: '修改成功' })
  72. }
  73. // emit('close')
  74. // emit('getList')
  75. router.back()
  76. } catch {
  77. //
  78. }
  79. }
  80. onMounted(async () => {
  81. if (route.query.id) {
  82. header.value = '编辑资讯'
  83. const { data } = await request.get(
  84. '/api-school/sysNewsInformation/detail/' + route.query.id
  85. )
  86. forms.linkUrl = data.linkUrl
  87. forms.coverImage = data.coverImage
  88. forms.summary = data.summary
  89. forms.title = data.title
  90. }
  91. })
  92. return () => (
  93. <div class={styles.addInformation}>
  94. <OHeader title={header.value} desotry={false} />
  95. <div class={styles.title}>
  96. <i class={[styles.icon, styles.icon1]}></i>请上传封面图片
  97. </div>
  98. <OUpload class={styles.upload} v-model:modelValue={forms.coverImage} />
  99. <div class={styles.title}>
  100. <i class={[styles.icon, styles.icon2]}></i>资讯标题
  101. </div>
  102. <Field
  103. placeholder="请输入资讯标题"
  104. class={styles.field}
  105. v-model={forms.title}
  106. autofocus={false}
  107. />
  108. <div class={styles.title}>
  109. <i class={[styles.icon, styles.icon3]}></i>内容简介
  110. </div>
  111. <Field
  112. placeholder="请输入资讯内容简要概述"
  113. type="textarea"
  114. rows={2}
  115. class={styles.field}
  116. v-model={forms.summary}
  117. autofocus={false}
  118. />
  119. <div class={styles.title}>
  120. <i class={[styles.icon, styles.icon4]}></i>添加链接
  121. </div>
  122. <Field placeholder="请输入链接" class={styles.field} v-model={forms.linkUrl} />
  123. <div class={'btnGroup'} style={{ marginTop: '24px' }}>
  124. <Button type="primary" block round onClick={onSubmit}>
  125. {!route.query.id ? '发布资讯' : '确认修改'}
  126. </Button>
  127. </div>
  128. </div>
  129. )
  130. }
  131. })