InfoForm.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <template>
  2. <div>
  3. <el-dialog
  4. :title="formTitle"
  5. :close-on-click-modal="false"
  6. dialogDrag
  7. width="1200px"
  8. @close="close"
  9. v-model="visible">
  10. <el-form size="middle" :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"
  11. label-width="90px" @submit.native.prevent>
  12. <el-row :gutter="15">
  13. <el-col :span="24">
  14. <el-form-item label="主题" prop="title"
  15. :rules="[
  16. {required: true, message:'主题不能为空', trigger:'blur'}
  17. ]">
  18. <el-input :disabled="method === 'view'" v-model="inputForm.title" placeholder="请填写主题"></el-input>
  19. </el-form-item>
  20. </el-col>
  21. <el-col :span="24">
  22. <el-form-item label="类型" prop="typeId"
  23. :rules="[
  24. {required: true, message:'分享类型不能为空', trigger:'blur'}
  25. ]">
  26. <el-select :disabled="method === 'view'" v-model="inputForm.typeId" placeholder="请选择" style="width:100%;">
  27. <el-option
  28. v-for="item in typeList"
  29. :value="item.id"
  30. :label="item.klgsType"
  31. :key="item.id">
  32. </el-option>
  33. </el-select>
  34. </el-form-item>
  35. </el-col>
  36. <el-col :span="24">
  37. <el-form-item label="内容" prop="detail"
  38. :rules="[
  39. {required: true, message:'内容不能为空', trigger:'blur'}
  40. ]">
  41. <WangEditor :disabled="method === 'view'" ref="contentEditor" v-model="inputForm.detail"
  42. @getUrl="(url, lsUrl) => {
  43. inputForm.editorFilesDTOList.push({temporaryUrl: lsUrl, url: url});
  44. }"/>
  45. </el-form-item>
  46. </el-col>
  47. </el-row>
  48. <!-- 附件 -->
  49. <UpLoadComponent ref="uploadComponent"></UpLoadComponent>
  50. <div v-if="method === 'view'">
  51. <el-divider v-if="method === 'view'" content-position="left"><i class="el-icon-document"></i>访问日志</el-divider>
  52. <div style="height: auto">
  53. <vxe-table
  54. border
  55. show-overflow
  56. v-if="method === 'view'"
  57. ref="detailTable"
  58. class="vxe-table-element"
  59. :data="inputForm.visits"
  60. @cell-click=""
  61. @edit-closed=""
  62. highlight-current-row
  63. >
  64. <vxe-table-column field="userName" title="访问人" :edit-render="{}">
  65. <template #default="scope">
  66. <el-input :readonly="true" :disbale="method === 'view'" v-model="scope.row.userName" >{{scope.row.userName}}</el-input>
  67. </template>
  68. </vxe-table-column>
  69. <vxe-table-column field="firstTime" title="首次访问时间" :edit-render="{}">
  70. <template #default="scope">
  71. <el-input :readonly="true" :disbale="method === 'view'" v-model="scope.row.firstTime" >{{scope.row.firstTime}}</el-input>
  72. </template>
  73. </vxe-table-column>
  74. <vxe-table-column field="lastTime" title="最近访问时间" :edit-render="{}">
  75. <template #default="scope">
  76. <el-input :readonly="true" :disbale="method === 'view'" v-model="scope.row.lastTime" >{{scope.row.lastTime}}</el-input>
  77. </template>
  78. </vxe-table-column>
  79. <vxe-table-column field="num" title="访问次数" :edit-render="{}">
  80. <template #default="scope">
  81. <el-input :readonly="true" :disbale="method === 'view'" v-model="scope.row.num" >{{scope.row.num}}</el-input>
  82. </template>
  83. </vxe-table-column>
  84. </vxe-table>
  85. <div class="tableLine"><span class="midText">共有{{inputForm.visitNum}}人访问 <el-link style="color: red" type="text" size="mini" v-show="inputForm.visitNum>3&&lookList" @click="findLogList(inputForm.visits.length)">查看全部</el-link></span></div>
  86. <n/>
  87. <el-divider></el-divider>
  88. </div>
  89. </div>
  90. <div v-if="method === 'view'">
  91. <el-form size="middle" :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''" :disabled="false" @submit.native.prevent>
  92. <el-divider v-if="method === 'view'" content-position="left"><i class="el-icon-document"></i>发表评论</el-divider>
  93. <el-row>
  94. <el-col>
  95. <el-form-item v-if="method === 'view'" prop="content">
  96. <el-input v-model="inputForm.content"
  97. type="textarea"
  98. :rows="5"
  99. :disabled="method !== 'view'"
  100. maxlength="500"
  101. placeholder="请输入评论信息"
  102. show-word-limit>
  103. </el-input>
  104. </el-form-item>
  105. </el-col>
  106. <el-button v-if="method === 'view'" style="float: right" type="primary" size="mini" @click="pushComment()" plain>
  107. 发表
  108. </el-button>
  109. <el-button v-if="method === 'view'" style="float: right; margin-right: 20px" type="primary" size="mini" @click="cleanComment()" plain>
  110. 清空
  111. </el-button>
  112. </el-row>
  113. <el-divider v-if="method === 'view'" content-position="left"><i class="el-icon-document"></i>全部评论({{inputForm.comments.length}}条)</el-divider>
  114. <div v-if="method === 'view'" v-for="(item, index) in inputForm.comments" v-show="index<initLength">
  115. <el-divider></el-divider>
  116. <div class="font_div" style="width: 100%; height:30px;"><span>{{item.userId}}</span></div>
  117. <div style="margin-left: 20px; height:45px;"><span>{{item.content}}</span></div>
  118. <div style="width: 100%; height:30px;">
  119. <span>{{item.deff}}</span>
  120. <a v-if="create === item.createBy || isAdmin" style="float: right" type="text" size="mini" @click="delComment(item.id)">删除</a>
  121. </div>
  122. </div>
  123. <el-divider></el-divider>
  124. <div class="tableLine"><span class="midText"><span v-show="inputForm.comments.length>3&&lookMore">还有{{inputForm.comments.length-3}}条评论</span> <el-link style="color: red" type="text" size="mini" v-show="inputForm.comments.length>3&&lookMore" @click="findComment(inputForm.comments.length)"> 查看全部</el-link></span></div>
  125. </el-form>
  126. </div>
  127. <KnowledgeShareTypePageForm ref="knowledgeShareTypePageForm" @getProgram="getProgram"></KnowledgeShareTypePageForm>
  128. </el-form>
  129. <template #footer>
  130. <span slot="footer" class="dialog-footer" style="float: right">
  131. <el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
  132. <el-button size="primary" type="primary" v-if="method != 'view'" @click="doSubmit()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
  133. </span>
  134. </template>
  135. </el-dialog>
  136. </div>
  137. </template>
  138. <script>
  139. import KnowledgeShareInfoService from '@/api/knowledgeShare/KnowledgeShareInfoService'
  140. import KnowledgeShareTypeService from '@/api/knowledgeShare/KnowledgeShareTypeService'
  141. import UpLoadComponent from '@/views/common/UpLoadComponent'
  142. import UserService from '@/api/sys/UserService'
  143. import KnowledgeShareTypePageForm from './KnowledgeShareTypePageForm'
  144. import WangEditor from '@/components/editor/WangEditor'
  145. export default {
  146. data () {
  147. return {
  148. lookMore:true,
  149. lookList:true,
  150. initLength:3,
  151. formTitle: '',
  152. method: '',
  153. visible: false,
  154. loading: false,
  155. isAdmin: false,
  156. create: '',
  157. typeList: [],
  158. inputForm: {
  159. id: '',
  160. typeId: '',
  161. title: '',
  162. detail: '',
  163. visits: [],
  164. comments: [],
  165. files: [],
  166. content: '',
  167. editorFilesDTOList: [],
  168. pageSize: 3,
  169. visitNum:''
  170. }
  171. }
  172. },
  173. knowledgeShareInfoService: null,
  174. created () {
  175. this.knowledgeShareInfoService = new KnowledgeShareInfoService()
  176. this.knowledgeShareTypeService = new KnowledgeShareTypeService()
  177. this.knowledgeShareTypeService.list().then((data) => {
  178. this.typeList = data.records
  179. })
  180. },
  181. computed :{
  182. bus: {
  183. get () {
  184. // this.$refs.uploadComponent.setDividerName('附件')
  185. return this.inputForm.id
  186. },
  187. set (val) {
  188. this.inputForm.id = val
  189. }
  190. },
  191. },
  192. watch: {
  193. 'keyWatch': {
  194. handler (newVal) {
  195. if (this.bus) {
  196. if (this.commonJS.isNotEmpty(this.bus)) {
  197. this.init('', this.bus)
  198. }
  199. } else {
  200. this.$nextTick(() => {
  201. this.$refs.inputForm.resetFields()
  202. })
  203. }
  204. }
  205. },
  206. // 'loading': {
  207. // handler (newVal) {
  208. // this.$emit('changeLoading', newVal)
  209. // this.$refs.uploadComponent.changeLoading(newVal)
  210. // }
  211. // }
  212. },
  213. components: {
  214. UpLoadComponent,
  215. KnowledgeShareTypePageForm,
  216. WangEditor
  217. },
  218. methods: {
  219. getKeyWatch (keyWatch) {
  220. this.keyWatch = keyWatch
  221. },
  222. init (method, id) {
  223. this.knowledgeShareTypeService.list().then((data) => {
  224. this.typeList = data.records
  225. })
  226. this.method = method
  227. this.inputForm = {
  228. id: '',
  229. typeId: '',
  230. typeName: '',
  231. title: '',
  232. detail: '',
  233. visits: [],
  234. comments: [],
  235. files: [],
  236. content: '',
  237. editorFilesDTOList: [],
  238. pageSize: 3,
  239. }
  240. if (method === 'add') {
  241. this.formTitle = `新建知识分享`
  242. } else if (method === 'edit') {
  243. this.inputForm.id = id
  244. this.formTitle = '修改知识分享'
  245. } else if (method === 'view') {
  246. this.inputForm.id = id
  247. this.formTitle = '查看知识分享'
  248. }
  249. this.visible = true
  250. this.loading = false
  251. this.$nextTick(() => {
  252. this.$refs.uploadComponent.setDividerName('附件')
  253. // if (method === 'add') {
  254. // this.$refs.contentEditor.enable()
  255. // }
  256. // if (method === 'edit' || method === 'view') { // 修改或者查看
  257. this.loading = true
  258. // 富文本处理
  259. this.$refs.contentEditor.clear()
  260. this.is()
  261. this.create = this.$store.state.user.id
  262. this.$refs.inputForm.resetFields()
  263. this.$refs.uploadComponent.clearUpload()
  264. this.knowledgeShareInfoService.findById(this.inputForm.id, method,this.inputForm.pageSize).then((data) => {
  265. console.log('data',data)
  266. this.inputForm.visitNum=data.visitNum
  267. // 富文本处理
  268. if (method === 'view') {
  269. this.$refs.contentEditor.disable()
  270. } else {
  271. this.$refs.contentEditor.enable()
  272. }
  273. this.inputForm = this.recover(this.inputForm, data)
  274. if (this.commonJS.isEmpty(this.inputForm.files)) {
  275. this.inputForm.files = []
  276. }
  277. // this.$refs.uploadComponent.newUpload(this.method, this.inputForm.files, 'knowledgeShare',null,null,null,null,false)
  278. this.inputForm = JSON.parse(JSON.stringify(this.inputForm))
  279. this.inputForm.comments = JSON.parse(JSON.stringify(this.inputForm.comments))
  280. // 富文本处理
  281. // if (this.commonJS.isNotEmpty(this.inputForm.detail)) {
  282. // this.$refs.contentEditor.init(this.inputForm.detail)
  283. // }
  284. this.$refs.uploadComponent.newUpload(this.method, this.inputForm.files, 'knowledgeShare')
  285. this.loading = false
  286. })
  287. // }
  288. })
  289. },
  290. // 表单提交
  291. doSubmit () {
  292. this.$refs['inputForm'].validate((valid) => {
  293. if (valid) {
  294. this.loading = true
  295. if (this.$refs.uploadComponent.checkProgress()) {
  296. this.loading = false
  297. return
  298. }
  299. if (this.commonJS.isEmpty(this.inputForm.files)) {
  300. this.inputForm.files = []
  301. }
  302. this.getEditorFilesDTOList()
  303. this.inputForm.files = this.$refs.uploadComponent.getDataList()
  304. this.knowledgeShareInfoService.save(this.inputForm).then((data) => {
  305. this.close()
  306. this.$message.success(data)
  307. this.loading = false
  308. }).catch(() => {
  309. this.loading = false
  310. })
  311. }
  312. })
  313. },
  314. close () {
  315. this.inputForm = {
  316. id: '',
  317. typeId: '',
  318. typeName: '',
  319. title: '',
  320. detail: '',
  321. visits: [],
  322. comments: [],
  323. files: [],
  324. content: '',
  325. editorFilesDTOList: []
  326. }
  327. this.$refs.inputForm.resetFields()
  328. this.$refs.uploadComponent.clearUpload()
  329. // 富文本处理
  330. this.$refs.contentEditor.clear()
  331. this.visible = false
  332. this.$emit('refreshDataList')
  333. this.lookMore=true,
  334. this.lookList=true,
  335. this.initLength=3
  336. },
  337. pushComment () {
  338. if (this.commonJS.isEmpty(this.inputForm.content)) {
  339. this.$message.error('请输入评论内容')
  340. return
  341. }
  342. this.commentForm = {
  343. detailId: this.inputForm.id,
  344. content: this.inputForm.content
  345. }
  346. this.loading = true
  347. this.knowledgeShareInfoService.addComment(this.commentForm).then((data) => {
  348. this.knowledgeShareInfoService.getComments(this.inputForm.id).then((da)=>{
  349. this.inputForm.comments = da.comments
  350. this.$message.success(data)
  351. this.inputForm.content = ""
  352. this.loading = false
  353. })
  354. })
  355. },
  356. cleanComment () {
  357. this.inputForm.content = ''
  358. },
  359. delComment (id) {
  360. this.knowledgeShareInfoService.delComment(id)
  361. this.init('view', this.inputForm.id)
  362. },
  363. is () {
  364. UserService.is().then(({data}) => {
  365. this.isAdmin = data
  366. })
  367. },
  368. // 知识分享类型弹窗选择
  369. openProgramPageForm () {
  370. this.$refs.knowledgeShareTypePageForm.init()
  371. },
  372. getProgram (rows) {
  373. this.inputForm.typeId = rows[0].id
  374. this.inputForm.typeName = rows[0].klgsType
  375. this.$forceUpdate()
  376. },
  377. getEditorFilesDTOList () {
  378. let a = []
  379. if (this.commonJS.isNotEmpty(this.inputForm.editorFilesDTOList)) {
  380. this.inputForm.detail = this.inputForm.detail.replace(/&amp;/g, '&')
  381. this.inputForm.editorFilesDTOList.forEach((item) => {
  382. if (this.inputForm.detail.includes(item.temporaryUrl)) {
  383. a.push(item)
  384. }
  385. })
  386. }
  387. this.inputForm.editorFilesDTOList = []
  388. a.forEach((item) => {
  389. this.inputForm.editorFilesDTOList.push(item)
  390. })
  391. },
  392. findComment(leg){
  393. this.lookMore=false
  394. this.initLength=leg
  395. },
  396. findLogList(){
  397. this.loading = true
  398. this.inputForm.pageSize=999999999
  399. console.log('method',this.method)
  400. this.knowledgeShareInfoService.findById(this.inputForm.id, this.method,this.inputForm.pageSize).then((data) => {
  401. this.$refs.uploadComponent.clearUpload()
  402. console.log('data',data)
  403. this.inputForm.visitNum=data.visitNum
  404. // 富文本处理
  405. if (this.method === 'view') {
  406. this.$refs.contentEditor.disable()
  407. } else {
  408. this.$refs.contentEditor.enable()
  409. }
  410. this.inputForm = this.recover(this.inputForm, data)
  411. if (this.commonJS.isEmpty(this.inputForm.files)) {
  412. this.inputForm.files = []
  413. }
  414. this.$refs.uploadComponent.newUpload('view', this.inputForm.files, 'knowledgeShare')
  415. this.inputForm = JSON.parse(JSON.stringify(this.inputForm))
  416. this.inputForm.comments = JSON.parse(JSON.stringify(this.inputForm.comments))
  417. this.loading = false
  418. this.lookList=false
  419. })
  420. }
  421. }
  422. }
  423. </script>
  424. <style>
  425. .font_div {
  426. font-weight: bold; /*加粗*/
  427. }
  428. </style>