km-atom-knowledage.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <div :class="$style.wrapHeight">
  3. <div :class="$style.rowHeight">
  4. <km-tree-async
  5. ref="tree"
  6. :load-tree-data="loadTreeData"
  7. option-count="count"
  8. @treeSelectd="treeSelectd"
  9. />
  10. <div :class="$style.rightcard">
  11. <a-card>
  12. <sd-oa-table
  13. v-if="expressions.length > 0"
  14. ref="oaTable"
  15. :form-id="formId"
  16. :page-id="pageId"
  17. :columns="columns"
  18. :actions="actions"
  19. :filter-expressions="expressions"
  20. :show-selection="showDeleteBtn"
  21. :search-fields="['title']"
  22. :row-selection="{ type: 'radio' }"
  23. @formBtnClick="formBtnClick"
  24. @recordsDeleted="onRecordsDeleted"
  25. >
  26. <a
  27. slot="fldSubject"
  28. slot-scope="text, record"
  29. :title="text"
  30. @click="knowledageView(record)"
  31. >{{ text }}</a
  32. >
  33. <template v-slot:form="{ model }">
  34. <km-atom-table ref="atomTable" :model="model" :default-category="defaultCategory" />
  35. </template>
  36. </sd-oa-table>
  37. <!-- 导入文件 -->
  38. <a-modal
  39. :footer="null"
  40. :title="modalImport.title"
  41. :visible="modalImport.visible"
  42. :width="650"
  43. destroy-on-close
  44. :mask-closable="false"
  45. @cancel="() => (modalImport.visible = false)"
  46. >
  47. <a-form>
  48. <a-form-item :wrapper-col="{ span: 12, offset: 6 }">
  49. <sd-attachment
  50. :max="1"
  51. :group-id="filegroupid"
  52. accept=".xls,.xlsx"
  53. @change="importfromfile"
  54. >
  55. </sd-attachment>
  56. </a-form-item>
  57. <a-form-item :wrapper-col="{ span: 12, offset: 6 }">
  58. <a-button type="link" @click="fnDownloadTemplate">
  59. 点此下载模板
  60. </a-button>
  61. </a-form-item>
  62. </a-form>
  63. </a-modal>
  64. </a-card>
  65. </div>
  66. </div>
  67. </div>
  68. </template>
  69. <script>
  70. import { Message, Modal } from 'ant-design-vue'
  71. import { getUserPerms } from '@/common/store-mixin'
  72. import download from '@/common/services/download'
  73. import TableActionTypes from '@/common/services/table-action-types'
  74. import TableColumnTypes from '@/common/services/table-column-types'
  75. import KmKnowledageService from '../km-knowledage-service'
  76. import components from './_import-components/km-atom-knowledage-import'
  77. const formData = new FormData()
  78. export default {
  79. name: 'KmAtomKnowledage',
  80. metaInfo: {
  81. title: '原子知识',
  82. },
  83. components,
  84. data() {
  85. return {
  86. formId: 'kmKnowledge',
  87. pageId: 'knowledge/kmAtom/kmAtom',
  88. expressions: [],
  89. formHomeId: '',
  90. columns: [
  91. {
  92. title: '标题',
  93. dataIndex: 'title',
  94. scopedSlots: { customRender: 'fldSubject' },
  95. },
  96. {
  97. title: '贡献者',
  98. dataIndex: 'creatorName',
  99. },
  100. {
  101. title: '所属分类',
  102. dataIndex: 'categoryName',
  103. },
  104. {
  105. title: '分类id',
  106. dataIndex: 'categoryId',
  107. sdHidden: true,
  108. },
  109. {
  110. title: '阅读次数',
  111. dataIndex: 'readTimes',
  112. },
  113. {
  114. title: '创建时间',
  115. dataIndex: 'creationTime',
  116. sdRender: TableColumnTypes.dateTime,
  117. },
  118. ],
  119. modalImport: {
  120. title: '导入原子知识',
  121. visible: false,
  122. formData,
  123. },
  124. groupid: Math.floor(Math.random()) * 10 + 1,
  125. filegroupid: 'atom_' + new Date().getTime().toString(16) + '_' + this.groupid,
  126. defaultCategory: '',
  127. showCreateBtn: false,
  128. showDeleteBtn: false,
  129. showImportBtn: false,
  130. showEditBtn: false,
  131. }
  132. },
  133. computed: {
  134. actions() {
  135. const actions = []
  136. if (this.showCreateBtn) {
  137. actions.push({
  138. label: '新建',
  139. id: 'creat',
  140. type: TableActionTypes.oa.create,
  141. })
  142. }
  143. if (this.showDeleteBtn) {
  144. actions.push({
  145. label: '删除',
  146. id: 'delete',
  147. type: TableActionTypes.oa.delete,
  148. })
  149. }
  150. if (this.showImportBtn) {
  151. actions.push({
  152. label: '导入',
  153. id: 'export',
  154. permission: null,
  155. callback: () => {
  156. this.modalImport.visible = true
  157. this.groupid = Math.floor(Math.random() * 100) + 1
  158. this.filegroupid = 'atom_' + new Date().getTime().toString(16) + '_' + this.groupid
  159. },
  160. })
  161. }
  162. if (this.showEditBtn) {
  163. actions.push({
  164. label: '编辑',
  165. id: 'edit',
  166. type: TableActionTypes.inline,
  167. callback: (record) => {
  168. this.$refs.oaTable.showDetailModal(record.id, this.pageId)
  169. },
  170. })
  171. }
  172. return actions
  173. },
  174. },
  175. created() {
  176. // 判断权限
  177. const userPerms = getUserPerms()
  178. if ('kmAtomKnowledge-create' in userPerms) {
  179. this.showCreateBtn = true
  180. }
  181. if ('kmAtomKnowledge-delete' in userPerms) {
  182. this.showDeleteBtn = true
  183. }
  184. if ('kmAtomKnowledge-import' in userPerms) {
  185. this.showImportBtn = true
  186. }
  187. if ('kmAtomKnowledge-update' in userPerms) {
  188. this.showEditBtn = true
  189. }
  190. },
  191. methods: {
  192. // 获取分类树
  193. loadTreeData(parentCatId) {
  194. const params = {
  195. pageId: 'atomKnowledge',
  196. categoryId: parentCatId || 0,
  197. }
  198. return KmKnowledageService.getKnowledgeTree(params).then((res) => {
  199. return res.data
  200. })
  201. },
  202. onRecordsDeleted() {
  203. this.$refs.tree.refresh() // 刷新树
  204. },
  205. // 查看数据
  206. knowledageView(record) {
  207. setTimeout(() => {
  208. this.$refs.oaTable.refresh()
  209. }, 5000)
  210. window.open(
  211. `#/km-knowledage-view?id=${record.id}&title=${record.title}&typeId=${record.categoryId}&typeName=${record.categoryName}`,
  212. '_blank'
  213. )
  214. },
  215. // 树选择节点后获取列表数据
  216. treeSelectd(item) {
  217. this.num++
  218. let parentId = ''
  219. let parentName = ''
  220. if (item.id !== undefined) {
  221. parentId = item.id
  222. parentName = item.text
  223. } else {
  224. parentId = item.selectedNodes[0].data.props.id
  225. parentName = item.selectedNodes[0].data.props.text
  226. }
  227. const obj = {
  228. id: parentId,
  229. name: parentName,
  230. }
  231. this.defaultCategory = [obj]
  232. this.selectdParentId = parseInt(parentId)
  233. this.selectdParentName = parentName
  234. const filter = [
  235. {
  236. dataType: 'str',
  237. name: 'categoryId',
  238. op: 'eq',
  239. stringValue: this.selectdParentId,
  240. },
  241. {
  242. dataType: 'str',
  243. name: 'type',
  244. op: 'eq',
  245. stringValue: '1',
  246. },
  247. {
  248. dataType: 'int',
  249. name: 'atomState',
  250. op: 'gt',
  251. stringValue: 0, // 1:已发布,0:草稿
  252. },
  253. ]
  254. this.expressions = filter
  255. },
  256. // 保存和发布
  257. formBtnClick(evt, btn, { form, recordId }) {
  258. switch (btn.buttonId) {
  259. case 'save': {
  260. evt.waitUntil(
  261. new Promise((resolve, reject) => {
  262. form.setFieldValue('atomState', 1)
  263. resolve()
  264. })
  265. )
  266. break
  267. }
  268. case 'keep': {
  269. evt.waitUntil(
  270. new Promise((resolve, reject) => {
  271. if (form.getFieldValue('atomState') === undefined) {
  272. form.setFieldValue('atomState', 0)
  273. }
  274. form.saveBtnClick()
  275. resolve()
  276. })
  277. )
  278. break
  279. }
  280. default:
  281. break
  282. }
  283. },
  284. // Excel导入原子知识
  285. importfromfile(data) {
  286. const key = Symbol.for()
  287. const hide = Message.loading({ content: '处理中...', key })
  288. KmKnowledageService.importAtom(data[0])
  289. .then((res) => {
  290. hide()
  291. const h = this.$createElement
  292. const reverseArray = res.data.reverse()
  293. const content = reverseArray.map((item) => {
  294. return h('p', {}, item)
  295. })
  296. Modal.info({
  297. title: '上传成功',
  298. content: h('div', {}, content),
  299. })
  300. this.$refs.oaTable.refresh()
  301. })
  302. .catch((err) => {
  303. Message.error(err)
  304. })
  305. this.modalImport.visible = false
  306. },
  307. // 下载原子知识模板
  308. fnDownloadTemplate() {
  309. KmKnowledageService.downloadAtomTemplateExcel().then((res) => {
  310. const url = URL.createObjectURL(res.data)
  311. const fname = '原子知识模板.xlsx'
  312. download(url, fname)
  313. })
  314. },
  315. },
  316. }
  317. </script>
  318. <style module lang="scss">
  319. @use '@/common/design' as *;
  320. .wrap-height {
  321. height: 100%;
  322. .row-height {
  323. display: flex;
  324. flex: auto;
  325. height: 100%;
  326. .rightcard {
  327. flex: 1;
  328. width: calc(100% - 20%);
  329. height: 100%;
  330. }
  331. }
  332. }
  333. </style>