company-rule.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <HcCard title="公司制度数据">
  3. <template #extra>
  4. <el-button hc-btn type="primary" @click="addUploadFile">
  5. 上传新制度
  6. </el-button>
  7. </template>
  8. <HcTable :column="tableColumn" :datas="tableData" :table-loading="tableLoading">
  9. <template #originalName="{ row }">
  10. <div class="text-link text-blue" @click="viewPdf(row)">
  11. {{ row?.originalName }}
  12. </div>
  13. </template>
  14. <template #action="{ row, index }">
  15. <el-button type="primary" size="small" @click="replaceUploadFile(row)">
  16. 重新上传
  17. </el-button>
  18. </template>
  19. </HcTable>
  20. <template #action>
  21. <HcPages :pages="searchForm" @change="pageChange" />
  22. </template>
  23. <!-- 上传组件 -->
  24. <HcUploadFile ref="uploadFileRef" :options="uploadOptions" :params="uploadParams" @success="uploadFileSuccess" />
  25. </HcCard>
  26. </template>
  27. <script setup>
  28. import { onActivated, ref } from 'vue'
  29. import { getTokenHeader } from '~src/api/request/header'
  30. import mainApi from '~api/people/companyRule.js'
  31. import { getArrValue } from 'js-fast-way'
  32. onActivated(() => {
  33. getTableData()
  34. })
  35. const searchForm = ref({
  36. current: 1, size: 20, total: 0,
  37. })
  38. //分页被点击
  39. const pageChange = ({ current, size }) => {
  40. searchForm.value.current = current
  41. searchForm.value.size = size
  42. getTableData()
  43. }
  44. //表格数据
  45. const tableColumn = [
  46. { key: 'originalName', name: '制度名称' },
  47. { key: 'action', name: '操作', width: 120 },
  48. ]
  49. const tableData = ref([])
  50. //获取表格数据
  51. const tableLoading = ref(false)
  52. const getTableData = async () => {
  53. tableLoading.value = true
  54. const { error, code, data } = await mainApi.getPage(searchForm.value)
  55. tableLoading.value = false
  56. if (!error && code === 200) {
  57. tableData.value = getArrValue(data['records'])
  58. searchForm.value.total = data['total'] || 0
  59. } else {
  60. tableData.value = []
  61. searchForm.value.total = 0
  62. }
  63. }
  64. //上传配置
  65. const uploadFileRef = ref(null)
  66. const uploadParams = ref({})
  67. const uploadOptions = {
  68. url: '/api/blade-control/corporationinfo/put-corporationinfo',
  69. headers: getTokenHeader(),
  70. multiple: false,
  71. size: 50,
  72. }
  73. //新增上传
  74. const addUploadFile = () => {
  75. uploadParams.value = {}
  76. uploadFileRef.value?.selectFile()
  77. }
  78. //重新上传
  79. const replaceUploadFile = (row) => {
  80. uploadParams.value = { id: row.id }
  81. uploadFileRef.value?.selectFile()
  82. }
  83. //上传完成
  84. const uploadFileSuccess = (res) => {
  85. uploadFileRef.value?.setModalShow(false)
  86. getTableData()
  87. }
  88. //查看pdf
  89. const viewPdf = ({ linkUrl }) => {
  90. if (linkUrl) {
  91. window.open(linkUrl, '_blank')
  92. } else {
  93. window.$message.error('暂无文件')
  94. }
  95. }
  96. </script>
  97. <style lang='scss' scoped>
  98. </style>