notes.vue 7.9 KB

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