documentEditPage.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <!-- 新增/编辑 文章页 -->
  3. <div class="document-edit-page">
  4. <div class="document-info page-block-wrap">
  5. <el-form
  6. ref="formRef"
  7. label-position="left"
  8. hide-required-asterisk
  9. :model="fileForm"
  10. :rules="fileFormRules"
  11. >
  12. <el-form-item label-width="118px" :label="$t('SemanticsManage.DocumentComparison.document_name')" prop="Title">
  13. <el-input
  14. v-model="fileForm.Title"
  15. style="width: 240px"
  16. :placeholder="$t('SemanticsManage.DocumentComparison.select_documents_input')"
  17. />
  18. </el-form-item>
  19. <!-- <el-form-item label="文档主题" prop="Theme">
  20. <el-input
  21. v-model="fileForm.Theme"
  22. style="width: 240px"
  23. placeholder="请输入文档主题"
  24. />
  25. </el-form-item> -->
  26. <el-form-item label-width="80px" :label="$t('SemanticsManage.DocumentComparison.select_category')" prop="ClassifyId">
  27. <el-select :placeholder="$t('SemanticsManage.DocumentComparison.please_select_category')" v-model="fileForm.ClassifyId">
  28. <el-option
  29. v-for="item in classifyOptions" :key="item.SaDocClassifyId"
  30. :label="item.ClassifyName"
  31. :value="item.SaDocClassifyId"
  32. />
  33. </el-select>
  34. </el-form-item>
  35. </el-form>
  36. <el-button type="primary" style="margin-left:auto;" @click="saveFile">{{$t('Dialog.confirm_save_btn')}}</el-button>
  37. <el-button @click="cancelModify">{{$t('Dialog.cancel_btn')}}</el-button>
  38. </div>
  39. <div class="document-content page-block-wrap" v-if="$route.path.includes('add')">
  40. <froala :id="`froala-editor-documentContent`"
  41. :ref="`froalaEditorDocumentContent`"
  42. :tag="'textarea'"
  43. :config="{...froalaConfig,placeholderText:$t('SemanticsManage.DocumentComparison.article_content_enter')}"
  44. v-model="documentContent"></froala>
  45. </div>
  46. <div class="document-content page-block-wrap overflow-hide-scrollbar" v-else>
  47. <div class="content-block">
  48. <div class="block-item" v-for="(item,index) in fileBlockArr" :key="index">
  49. <!-- 若段落内有选定文字被打标签 item.UsePartNum 则不允许编辑段落内容 -->
  50. <textarea v-model="item.innerText" :placeholder="$t('SemanticsManage.DocumentComparison.paragraph_content_ipt')" :disabled="item.UsePartNum!==0"></textarea>
  51. <div class="block-item-tool">
  52. <div class="add-btn" @click="addBlock(index)">
  53. <img
  54. src="~@/assets/img/set_m/add_ico.png"
  55. alt=""
  56. style="width: 14px; height: 14px; margin-right: 10px"
  57. />
  58. <span>{{$t('SemanticsManage.DocumentComparison.add_next_section')}}</span>
  59. </div>
  60. <div class="dele-btn" style="margin-left:30px;margin-right:auto;"
  61. v-if="item.UseNum+item.UsePartNum===0" @click="deleteBlock(index)">
  62. <img
  63. src="~@/assets/img/set_m/del_icon.png"
  64. alt=""
  65. style="width: 14px; height: 14px; margin-right: 10px"
  66. />
  67. <span>{{$t('Table.delete_btn')}}</span>
  68. </div>
  69. <p class="hint-text">{{$t('SemanticsManage.DocumentComparison.number_tags_attached')}}:{{item.UseNum+item.UsePartNum}}</p>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. </template>
  76. <script>
  77. import {froalaConfig} from '../utils/config';
  78. import {formatFile} from '../utils/index';
  79. import {documentInterface} from '@/api/modules/semanticsApi.js';
  80. export default {
  81. data() {
  82. return {
  83. documentContent:'',//文档内容
  84. froalaConfig:froalaConfig,//富文本配置
  85. fileForm:{Title:'',/* Theme:'', */ClassifyId:''},//文档信息
  86. classifyOptions:[],//分类列表
  87. fileBlockArr:[],//文档段落列表
  88. fileId:0,//为0时是新增 不为0时是文档id
  89. };
  90. },
  91. methods: {
  92. //获取分类列表
  93. getClassifyList(){
  94. documentInterface.getClassifyList().then(res=>{
  95. if(res.Ret!==200) return
  96. this.classifyOptions = res.Data||[]
  97. })
  98. },
  99. //获取文档详情
  100. getFileData(){
  101. const {fileId} = this.$route.query
  102. if(fileId&&Number(fileId.split('_')[1])){
  103. this.fileId = Number(fileId.split('_')[1])
  104. documentInterface.getDocumentDetail({DocId:this.fileId}).then(res=>{
  105. if(res.Ret!==200) return
  106. const {Title,/* Theme, */ClassifyId} = res.Data
  107. this.fileForm = {
  108. Title,/* Theme, */ClassifyId
  109. }
  110. this.fileBlockArr = formatFile(res.Data).SectionList
  111. })
  112. }else{
  113. this.fileForm = {Title:'',/* Theme:'', */ClassifyId:''}
  114. }
  115. },
  116. //添加一段
  117. addBlock(index){
  118. let block = {
  119. SaDocSectionId:0,
  120. DocId:this.fileId,
  121. Content:'',
  122. innerText:'',
  123. Sort:index+1,//其实这个无所谓
  124. UseNum:0,
  125. UsePartNum:0
  126. }
  127. this.fileBlockArr.splice(index+1,0,block)
  128. },
  129. //删除一段
  130. deleteBlock(index){
  131. if(index===0&&this.fileBlockArr.length===1){
  132. this.$message.warning(this.$t('SemanticsManage.DocumentComparison.least_one_paragraph_msg') )
  133. return
  134. }
  135. this.fileBlockArr.splice(index,1)
  136. },
  137. //点击保存按钮
  138. async saveFile(){
  139. //每个段落都有值
  140. if(!this.checkBlock()) return
  141. //文章有内容
  142. if(!this.fileId&&!this.documentContent.length){
  143. this.$message.warning(this.$t('SemanticsManage.DocumentComparison.article_content_enter') )
  144. return
  145. }
  146. let flag = false
  147. this.$refs.formRef.validate((valid) => {
  148. flag = valid
  149. })
  150. //文档信息已填写
  151. if(!flag) return
  152. if(this.fileId===0){
  153. this.addFile()
  154. }else{
  155. this.editFile()
  156. }
  157. },
  158. //新增文档
  159. addFile(){
  160. const {Title,/* Theme, */ClassifyId} = this.fileForm
  161. documentInterface.addDocument({
  162. Title,/* Theme, */ClassifyId,Content:this.documentContent
  163. }).then(res=>{
  164. if(res.Ret!==200) return
  165. this.$message.success(this.$t('MsgPrompt.add_msg'))
  166. const SaDocId = res.Data?res.Data:''
  167. sessionStorage.setItem('fileClassify',ClassifyId+'')
  168. sessionStorage.setItem('fileId',SaDocId+'')
  169. this.$router.push('/documentPage')
  170. })
  171. },
  172. //编辑文档
  173. editFile(){
  174. const {Title,/* Theme, */ClassifyId} = this.fileForm
  175. //按index排序fileBlockArr
  176. this.fileBlockArr = this.fileBlockArr.map((item,index)=>{
  177. item.Sort = index+1
  178. item.Content = item.innerText
  179. return item
  180. })
  181. documentInterface.editDocument({
  182. SaDocId:this.fileId,
  183. Title,/* Theme, */ClassifyId,
  184. SectionList:this.fileBlockArr
  185. }).then(res=>{
  186. if(res.Ret!==200) return
  187. this.$message.success(this.$t('MsgPrompt.edit_msg'))
  188. sessionStorage.setItem('fileClassify',ClassifyId+'')
  189. sessionStorage.setItem('fileId',this.fileId+'')
  190. this.$router.push('/documentPage')
  191. })
  192. },
  193. cancelModify(){
  194. if(this.fileId!==0){
  195. sessionStorage.setItem('fileClassify',this.fileForm.ClassifyId+'')
  196. sessionStorage.setItem('fileId',this.fileId+'')
  197. }
  198. this.$router.push('/documentPage')
  199. },
  200. checkBlock(){
  201. for(let i=0;i<this.fileBlockArr.length;i++){
  202. if(!this.fileBlockArr[i].innerText.length){
  203. this.$message.warning(this.$t('SemanticsManage.DocumentComparison.paragraph_content_ipt') )
  204. return false
  205. }
  206. }
  207. return true
  208. },
  209. },
  210. mounted(){
  211. this.$refs.formRef.resetFields();
  212. this.getFileData()
  213. this.getClassifyList()
  214. },
  215. computed: {
  216. fileFormRules() {
  217. return {
  218. Title: [{ required: true, message: this.$t('SemanticsManage.DocumentComparison.document_name_no_empty') }],
  219. /* Theme:[
  220. { required: true, message: "文档主题不能为空"}
  221. ], */
  222. ClassifyId: [{ required: true, message: this.$t('SemanticsManage.DocumentManagement.select_document_category_msg') }],
  223. };
  224. },
  225. },
  226. };
  227. </script>
  228. <style lang="scss">
  229. .document-fr-custom-class{
  230. height: 100%;
  231. display: flex;
  232. flex-direction: column;
  233. .fr-wrapper{
  234. flex: 1;
  235. .fr-element{
  236. height:100%
  237. }
  238. }
  239. }
  240. </style>
  241. <style scoped lang="scss">
  242. @import "../css/basePage.scss";
  243. .document-edit-page{
  244. display: flex;
  245. flex-direction: column;
  246. width: 100%;
  247. height: calc(100vh - 120px);
  248. .document-info{
  249. padding:20px 30px;
  250. display: flex;
  251. justify-content: space-between;
  252. .el-form{
  253. display: flex;
  254. .el-form-item{
  255. margin-right: 30px;
  256. margin-bottom: 0px;
  257. }
  258. }
  259. }
  260. .document-content{
  261. margin-top: 20px;
  262. flex: 1;
  263. padding: 30px;
  264. &.overflow-hide-scrollbar{
  265. overflow-y: scroll;
  266. }
  267. .content-block{
  268. .block-item{
  269. margin-bottom: 25px;
  270. textarea{
  271. width:100%;
  272. height:180px;
  273. border: 1px solid #DCDFE6;
  274. padding:5px 15px;
  275. border-radius: 4px;
  276. font-size: 18px;
  277. color:#666666;
  278. line-height: 28px;
  279. resize: vertical;
  280. }
  281. .block-item-tool{
  282. margin-top: 5px;
  283. color: #409eff;
  284. display: flex;
  285. justify-content: space-between;
  286. align-items: center;
  287. font-size: 14px;
  288. .add-btn,.dele-btn{
  289. cursor: pointer;
  290. display: flex;
  291. align-items: center;
  292. }
  293. .dele-btn{
  294. color:#C54322;
  295. }
  296. .hint-text{
  297. color:#999999;
  298. }
  299. }
  300. }
  301. }
  302. }
  303. }
  304. </style>