news2.vue 8.8 KB

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