index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div class="main " v-loading="loading">
  3. <custom-search-bar :fields="fields.filter((f) => f.isSearch)" v-model="searchForm" @search="search" @reset="toReset"> </custom-search-bar>
  4. <custom-button-bar :fields="buttonFields" @add="toAdd" @select="toMoreDelect"></custom-button-bar>
  5. <custom-table :data="data" :fields="fields" @query="search" :total="total" :opera="opera" @journal="toJournal" @exam="toExam" @edit="toEdit" @delete="toDelete" @toSelect="toSelect">
  6. <template #is_use="{ row }">
  7. <el-tag v-if="row.is_use == '0'" type="success" @click="toUse(row, '1')">启用</el-tag>
  8. <el-tag v-else type="info" @click="toUse(row, '0')">禁用</el-tag>
  9. </template>
  10. </custom-table>
  11. <el-dialog v-model="dialog.show" :title="dialog.title" :destroy-on-close="false" @close="toClose">
  12. <el-row>
  13. <el-col :span="24" v-if="dialog.type == '1'">
  14. <custom-form v-model="form" :fields="formFields" :rules="rules" @save="toSave">
  15. <template #file>
  16. <custom-upload model="file" :list="form.file" :limit="1" listType="picture-card" url="/files/web/cxyy_journal/upload" @change="onUpload"></custom-upload>
  17. </template>
  18. <template #is_use>
  19. <el-radio v-for="i in isUseList" :key="i.id" :label="i.value">{{ i.label }}</el-radio>
  20. </template>
  21. </custom-form>
  22. </el-col>
  23. <el-col :span="24" v-if="dialog.type == '2'">
  24. <custom-form v-model="examForm" :fields="examFormFields" :rules="examRules" @save="toExamSave">
  25. <template #status>
  26. <el-option v-for="i in statusList" :key="i.id" :label="i.label" :value="i.value"></el-option>
  27. </template>
  28. </custom-form>
  29. </el-col>
  30. </el-row>
  31. </el-dialog>
  32. </div>
  33. </template>
  34. <script setup>
  35. import { cloneDeep, get } from 'lodash-es'
  36. const $checkRes = inject('$checkRes')
  37. const { t } = useI18n()
  38. // 接口
  39. import { JournalStore } from '@/store/api/platform/journal'
  40. import { DictDataStore } from '@/store/api/system/dictData'
  41. const store = JournalStore()
  42. const dictDataStore = DictDataStore()
  43. // 路由
  44. const router = useRouter()
  45. const data = ref([])
  46. const searchForm = ref({})
  47. const fields = [
  48. { label: t('pages.journal.name'), model: 'name', isSearch: true },
  49. { label: t('pages.journal.is_use'), model: 'is_use', custom: true, format: (i) => getDict(i, 'is_use') },
  50. { label: t('pages.journal.status'), model: 'status', format: (i) => getDict(i, 'status') }
  51. ]
  52. const opera = [
  53. { label: t('common.journal'), method: 'journal' },
  54. { label: t('common.update'), method: 'edit' },
  55. { label: t('common.exam'), method: 'exam', type: 'warning', display: (i) => i.status === '0' },
  56. { label: t('common.delete'), method: 'delete', confirm: true, type: 'danger', display: (i) => i.is_use === '1' }
  57. ]
  58. const buttonFields = [
  59. { label: t('common.create'), method: 'add' },
  60. ]
  61. let skip = 0
  62. let limit = inject('limit')
  63. const total = ref(0)
  64. // 字典表
  65. const isUseList = ref([])
  66. const statusList = ref([])
  67. // 多选列表
  68. const selectList = ref([])
  69. // 加载中
  70. const loading = ref(false)
  71. const formFields = ref([
  72. { label: t('pages.journal.file'), model: 'file', custom: true },
  73. { label: t('pages.journal.name'), model: 'name' },
  74. { label: t('pages.journal.sort'), model: 'sort', type: 'number' },
  75. { label: t('pages.journal.is_use'), model: 'is_use', type: 'radio' },
  76. { label: t('pages.journal.brief'), model: 'brief', type: 'textarea' }
  77. ])
  78. const rules = reactive({ name: [{ required: true, message: t('pages.journal.titleMessage'), trigger: 'blur' }] })
  79. const dialog = ref({ type: '1', show: false, title: t('pages.journal.addDialogTitle') })
  80. const form = ref({ file: [] })
  81. // 审核
  82. const examFormFields = [{ label: t('pages.journal.status'), model: 'status', type: 'select' }]
  83. const examRules = reactive({ status: [{ required: true, message: t('common.statusMessage'), trigger: 'blur' }] })
  84. const examForm = ref({})
  85. // 请求
  86. onMounted(async () => {
  87. loading.value = true
  88. await searchOther()
  89. await search({ skip, limit })
  90. loading.value = false
  91. })
  92. const searchOther = async () => {
  93. let result
  94. // 是否使用
  95. result = await dictDataStore.query({ code: 'isUse', is_use: '0' })
  96. if ($checkRes(result)) isUseList.value = result.data
  97. // 状态
  98. result = await dictDataStore.query({ code: 'examStatus', is_use: '0' })
  99. if ($checkRes(result)) statusList.value = result.data
  100. }
  101. const search = async (query = { skip, limit }) => {
  102. skip = query.skip
  103. limit = query.limit
  104. const info = { skip: query.skip, limit: query.limit, ...searchForm.value }
  105. const res = await store.query(info)
  106. if (res.errcode == '0') {
  107. data.value = res.data
  108. total.value = res.total
  109. }
  110. }
  111. // 字典数据转换
  112. const getDict = (data, model) => {
  113. if (data) {
  114. let res
  115. if (model == 'is_use') res = isUseList.value.find((f) => f.value == data)
  116. else if (model == 'status') res = statusList.value.find((f) => f.value == data)
  117. return get(res, 'label')
  118. }
  119. }
  120. // 多选
  121. const toSelect = (val) => {
  122. selectList.value = val
  123. }
  124. // 批量删除
  125. const toMoreDelect = () => {
  126. if (selectList.value.length > 0) {
  127. ElMessageBox.confirm(`确定批量删除数据?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  128. .then(async () => {
  129. console.log(selectList.value)
  130. })
  131. .catch(() => {})
  132. } else {
  133. ElMessage({
  134. message: '未选择要处理的数据!',
  135. type: 'warning'
  136. })
  137. }
  138. }
  139. // 添加
  140. const toAdd = () => {
  141. form.value = { file: [] }
  142. dialog.value = { type: '1', show: true, title: t('pages.journal.addDialogTitle') }
  143. }
  144. // 修改
  145. const toEdit = (data) => {
  146. if (!data.file) data.file = []
  147. form.value = data
  148. dialog.value = { type: '1', show: true, title: t('pages.journal.upDialogTitle') }
  149. }
  150. // 删除
  151. const toDelete = async (data) => {
  152. const res = await store.del(data.id)
  153. if ($checkRes(res, true)) {
  154. search({ skip, limit })
  155. }
  156. }
  157. // 期刊管理
  158. const toJournal = (data) => {
  159. router.push({ path: '/journal/notes', query: { id: data.id } })
  160. }
  161. // 上传图片
  162. const onUpload = (e) => {
  163. const { model, value } = e
  164. form.value[model] = value
  165. }
  166. const toSave = async () => {
  167. const data = cloneDeep(form.value)
  168. const other = { status: '0' }
  169. let res
  170. if (get(data, 'id')) res = await store.update({ ...data, ...other })
  171. else res = await store.create({ ...data, ...other })
  172. if ($checkRes(res, true)) {
  173. search({ skip, limit })
  174. toClose()
  175. }
  176. }
  177. // 审核
  178. const toExam = (data) => {
  179. examForm.value = data
  180. dialog.value = { type: '2', show: true, title: t('pages.journal.examDialogTitle') }
  181. }
  182. // 审核保存
  183. const toExamSave = async () => {
  184. const data = cloneDeep(examForm.value)
  185. let res = await store.update({ id: data.id, status: data.status })
  186. if ($checkRes(res, true)) {
  187. search({ skip, limit })
  188. toClose()
  189. }
  190. }
  191. // 开启或禁用
  192. const toUse = async (data, is_use) => {
  193. ElMessageBox.confirm(`确定修改【${data.name}】数据?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
  194. .then(async () => {
  195. let res = await store.update({ id: get(data, 'id'), is_use, status: get(data, 'status') })
  196. if ($checkRes(res, true)) {
  197. search({ skip, limit })
  198. }
  199. })
  200. .catch(() => {})
  201. }
  202. // 重置
  203. const toReset = async () => {
  204. searchForm.value = {}
  205. await search({ skip, limit })
  206. }
  207. const toClose = () => {
  208. form.value = { file: [] }
  209. dialog.value = { show: false }
  210. }
  211. </script>
  212. <style scoped lang="scss"></style>