news1.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <div class="index">
  3. <el-row>
  4. <el-col :span="24" class="main" v-loading="loading">
  5. <el-col :span="24" class="one">
  6. <div class="one_left" @click="toAdd">发布赛事通知</div>
  7. <div class="one_right">
  8. <el-input v-model="searchForm.title" style="width: 250px" size="large" placeholder="搜索" @change="search" :suffix-icon="Search" />
  9. </div>
  10. </el-col>
  11. <el-col :span="24" class="two">
  12. <el-table :data="list" style="width: 100%" size="large" :header-cell-style="{ backgroundColor: '#edf3ff' }">
  13. <template #empty>
  14. <el-empty description="暂无数据" />
  15. </template>
  16. <el-table-column prop="title" align="center" label="标题" />
  17. <el-table-column prop="time" align="center" label="发布时间" width="180" />
  18. <el-table-column prop="status" align="center" label="状态" width="180">
  19. <template #default="scope">
  20. <div>{{ getDict(scope.row.status, 'status') }}</div>
  21. </template>
  22. </el-table-column>
  23. <el-table-column align="center" label="操作" width="180">
  24. <template #default="{ row }">
  25. <el-link v-if="row.status == '-2'" :underline="false" type="warning" size="mini" @click="toExam(row)" style="margin-right: 10px">提交审核</el-link>
  26. <el-link :underline="false" type="primary" size="mini" @click="toEdit(row)" style="margin-right: 10px">修改</el-link>
  27. <el-link :underline="false" type="danger" size="mini" @click="toDelete(row)"> 删除 </el-link>
  28. </template>
  29. </el-table-column>
  30. </el-table>
  31. </el-col>
  32. <el-col :span="24" class="thr">
  33. <el-pagination background layout="prev, pager, next" :total="total" :page-size="limit" v-model:current-page="currentPage" @current-change="changePage" @size-change="sizeChange" />
  34. </el-col>
  35. </el-col>
  36. </el-row>
  37. <el-dialog v-model="dialog.show" :title="dialog.title" :destroy-on-close="false" @close="toClose">
  38. <el-row>
  39. <el-col :span="24" v-if="dialog.type == '1'">
  40. <custom-form v-model="form" :fields="formFields" :rules="rules" @save="toSave" @draftSave="toDraftSave">
  41. <template #logo>
  42. <custom-upload model="logo" :list="form.logo" :limit="1" url="/files/web/cxyy_news/upload" @change="onUpload" listType="picture-card"></custom-upload>
  43. </template>
  44. <template #is_use>
  45. <el-radio v-for="i in isUseList" :key="i.id" :label="i.value">{{ i.label }}</el-radio>
  46. </template>
  47. <template #is_show>
  48. <el-radio v-for="i in isUseList" :key="i.id" :label="i.value">{{ i.label }}</el-radio>
  49. </template>
  50. <template #tags>
  51. <el-select v-model="form.tags" multiple filterable allow-create default-first-option :reserve-keyword="false" placeholder="请选择标签" style="width: 100%">
  52. <el-option v-for="item in tagsList" :key="item.id" :label="item.title" :value="item.title" />
  53. </el-select>
  54. </template>
  55. <template #content>
  56. <WangEditor v-model="form.content" />
  57. </template>
  58. </custom-form>
  59. </el-col>
  60. </el-row>
  61. </el-dialog>
  62. </div>
  63. </template>
  64. <script setup>
  65. import moment from 'moment'
  66. import { Search } from '@element-plus/icons-vue'
  67. import { cloneDeep, get } from 'lodash-es'
  68. const $checkRes = inject('$checkRes')
  69. import { UserStore } from '@/store/user'
  70. const userStore = UserStore()
  71. const user = computed(() => userStore.user)
  72. // 接口
  73. import { NewsStore } from '@/store/api/platform/news'
  74. import { DictDataStore } from '@/store/api/system/dictData'
  75. import { TagsStore } from '@/store/api/system/tags'
  76. const store = NewsStore()
  77. const dictDataStore = DictDataStore()
  78. const tagsStore = TagsStore()
  79. // 加载中
  80. const loading = ref(false)
  81. const searchForm = ref({})
  82. // 列表
  83. const list = ref([])
  84. let skip = 0
  85. let limit = inject('limit')
  86. const total = ref(0)
  87. const currentPage = ref(1)
  88. // 字典表
  89. const isUseList = ref([])
  90. const statusList = ref([])
  91. const tagsList = ref([])
  92. const form = ref({ logo: [], type: '1' })
  93. const dialog = ref({ type: '1', show: false, title: '发布行业动态' })
  94. const formFields = ref([
  95. { label: '封面', model: 'logo', custom: true },
  96. { label: '标题', model: 'title' },
  97. { label: '标签', model: 'tags', custom: true },
  98. { label: '发布人', model: 'person', options: { disabled: true } },
  99. { label: '发布时间', model: 'time', type: 'date', options: { disabled: true } },
  100. { label: '浏览量', model: 'number', options: { disabled: true } },
  101. { label: '是否公开', model: 'is_use', type: 'radio' },
  102. { label: '是否在首页显示', model: 'is_show', type: 'radio' },
  103. { label: '内容', model: 'content', custom: true }
  104. ])
  105. const rules = reactive({
  106. logo: [{ required: true, message: '请上传封面', trigger: 'blur' }],
  107. name: [{ required: true, message: '请输入标题', trigger: 'blur' }],
  108. content: [{ required: true, message: '请输入内容', trigger: 'blur' }]
  109. })
  110. // 请求
  111. onMounted(async () => {
  112. loading.value = true
  113. await searchOther()
  114. await search()
  115. loading.value = false
  116. })
  117. const search = async (query = { skip, limit }) => {
  118. skip = query.skip
  119. limit = query.limit
  120. const info = {
  121. skip: query.skip,
  122. limit: query.limit,
  123. user: user.value.id,
  124. type: '1',
  125. ...searchForm.value
  126. }
  127. const res = await store.query(info)
  128. if (res.errcode == '0') {
  129. list.value = res.data
  130. total.value = res.total
  131. }
  132. }
  133. const searchOther = async () => {
  134. let result
  135. // 是否使用
  136. result = await dictDataStore.query({ code: 'isUse', is_use: '0' })
  137. if ($checkRes(result)) isUseList.value = result.data
  138. // 状态
  139. result = await dictDataStore.query({ code: 'examStatus', is_use: '0' })
  140. if ($checkRes(result)) statusList.value = result.data
  141. // 标签
  142. result = await tagsStore.query({ is_use: '0' })
  143. if ($checkRes(result)) tagsList.value = result.data
  144. }
  145. // 字典数据转换
  146. const getDict = (data, model) => {
  147. if (data) {
  148. let res
  149. if (model == 'status') res = statusList.value.find((f) => f.value == data)
  150. return get(res, 'label')
  151. }
  152. }
  153. // 添加
  154. const toAdd = () => {
  155. form.value = { status: '0', type: '1', user: user.value.id, time: moment().format('YYYY-MM-DD'), person: user.value.nick_name }
  156. dialog.value = { type: '1', show: true, title: '发布行业动态' }
  157. }
  158. // 修改
  159. const toEdit = (data) => {
  160. form.value = data
  161. dialog.value = { type: '1', show: true, title: '修改行业动态' }
  162. }
  163. // 删除
  164. const toDelete = (data) => {
  165. ElMessageBox.confirm(`您确认删除${data.name}该数据?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  166. .then(async () => {
  167. const res = await store.del(data.id)
  168. if ($checkRes(res, true)) {
  169. search({ skip, limit })
  170. }
  171. })
  172. .catch(() => {})
  173. }
  174. const toSave = async () => {
  175. const data = cloneDeep(form.value)
  176. const other = { status: '0', type: '1', user: user.value.id, time: moment().format('YYYY-MM-DD'), person: user.value.nick_name }
  177. let res
  178. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  179. else res = await store.create({ ...data, ...other })
  180. if ($checkRes(res, true)) {
  181. search({ skip, limit })
  182. toClose()
  183. }
  184. }
  185. const toDraftSave = async () => {
  186. const data = cloneDeep(form.value)
  187. const other = { status: '-2', type: '1', user: user.value.id, time: moment().format('YYYY-MM-DD'), person: user.value.nick_name }
  188. let res
  189. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  190. else res = await store.create({ ...data, ...other })
  191. if ($checkRes(res, true)) {
  192. search({ skip, limit })
  193. toClose()
  194. }
  195. }
  196. // 审核保存
  197. const toExam = async (row) => {
  198. ElMessageBox.confirm(`您确认保存并提交审核该数据?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  199. .then(async () => {
  200. const data = cloneDeep(row)
  201. let res = await store.update({ id: data.id, status: '0', user: user.value.id })
  202. if ($checkRes(res, true)) {
  203. search({ skip, limit })
  204. toClose()
  205. }
  206. })
  207. .catch(() => {})
  208. }
  209. const toClose = () => {
  210. form.value = { logo: [], type: '1' }
  211. dialog.value = { show: false }
  212. }
  213. // 上传图片
  214. const onUpload = (e) => {
  215. const { model, value } = e
  216. form.value[model] = value
  217. }
  218. // 分页
  219. const changePage = (page = currentPage.value) => {
  220. search({ skip: (page - 1) * limit, limit: limit })
  221. }
  222. const sizeChange = (limits) => {
  223. limit = limits
  224. currentPage.value = 1
  225. search({ skip: 0, limit: limit })
  226. }
  227. </script>
  228. <style scoped lang="scss">
  229. .main {
  230. .one {
  231. height: 50px;
  232. display: flex;
  233. justify-content: space-between;
  234. align-items: center;
  235. margin: 0 0 10px 0;
  236. .one_left {
  237. background: #1875df;
  238. padding: 0 10px;
  239. height: 30px;
  240. color: #fff;
  241. line-height: 30px;
  242. text-align: center;
  243. font-size: 16px;
  244. cursor: default;
  245. }
  246. }
  247. .thr {
  248. display: flex;
  249. justify-content: center;
  250. margin: 20px 0 0 0;
  251. }
  252. }
  253. </style>