TraceCommentEdit.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <div>
  3. <div>
  4. <Navbar title="修改评论" :is-go-back="true" />
  5. <div>
  6. <div class="form-group">
  7. <label for="exampleInputEmail2">评论内容</label>
  8. <div id="summernote" />
  9. <!-- <textarea style="width: 100%;"
  10. id="hcqk"
  11. class="form-control"
  12. rows="5"
  13. v-model="traceComment.content"></textarea> -->
  14. </div>
  15. <div>
  16. <input ref="fileInput" autocomplete="off" type="file" class="form-control file-input" @change="onFileChanges" />
  17. <label for="attachment">
  18. <a role="button" class="btn btn-primary btn-sm" @click="clickButton">
  19. <i class="fa fa-upload" />
  20. &nbsp;
  21. 上传附件
  22. </a>
  23. </label>
  24. </div>
  25. <div style="margin-top: 10px;">
  26. <ul class="list-group">
  27. <li v-for="item in files" :key="item" class="list-group-item">
  28. <span class="badge" @click="download(item)">下载</span>
  29. <span class="badge" @click="removeFile(item)">删除</span>
  30. {{ item }}
  31. </li>
  32. </ul>
  33. </div>
  34. <div>
  35. <div style="margin-top: 10px;">
  36. <button type="text" class="btn btn-default" @click="photograph">确认</button>
  37. <button type="text" class="btn btn-default" @click="back">取消</button>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. <Loading v-if="loading" />
  43. </div>
  44. </template>
  45. <script>
  46. import UpladFile from '../widget/UpladFile.js';
  47. import Common from '../common/Common.js';
  48. import { DownloadService } from 'pc-component-v3';
  49. export default {
  50. components: {
  51. UpladFile,
  52. },
  53. data: function() {
  54. return {
  55. traceCommentId: '',
  56. traceComment: {},
  57. className: 'com.leanwo.prodog.trace.model.TraceComment',
  58. summernoteInitSuccess: false, // summernote初始化成功
  59. files: [],
  60. loading: false,
  61. };
  62. },
  63. mounted: function() {
  64. $('.input-tan').focus(function() {
  65. document.activeElement.blur();
  66. });
  67. this.initData();
  68. },
  69. methods: {
  70. /**
  71. * 点击上传按钮事件
  72. * @return {[type]} [description]
  73. */
  74. clickButton: function() {
  75. $(this.$refs.fileInput).click();
  76. },
  77. /**
  78. * 初始化数据
  79. * @author GuoZhiBo 20171201
  80. */
  81. initData: function() {
  82. var _self = this;
  83. _self.traceCommentId = Number(this.$route.params.traceCommentId);
  84. if (_self.traceCommentId != null && _self.traceCommentId != '') {
  85. _self.uniqueById(_self.traceCommentId).then(successData => {
  86. _self.traceComment = successData;
  87. if(successData.attachments != null && successData.attachments != ''){
  88. _self.files=(successData.attachments.split(','));
  89. }
  90. $('#summernote').summernote({
  91. toolbar:[
  92. ['insert', ['link', 'picture', 'video', 'audio', 'hr', 'table', //插件
  93. 'fontname', 'fontsize', 'color', 'bold', 'italic', 'underline', 'strikethrough', 'clear',//字体样式
  94. 'style', 'ol', 'ul', 'paragraph', 'height',//段落样式
  95. 'fullscreen', 'codeview', 'undo', 'redo', 'help',//Misc
  96. ]],
  97. ],
  98. height: 400,
  99. minHeight: 300,
  100. maxHeight: 500,
  101. focus: true,
  102. lang: 'zh-CN',
  103. callbacks: {
  104. onImageUpload: function(files, editor, $editable) {
  105. _self.sendFile(files[0], editor, $editable);
  106. },
  107. },
  108. });
  109. if (_self.traceComment != null) {
  110. $('#summernote').summernote('code', _self.traceComment.content);
  111. }
  112. _self.summernoteInitSuccess = true;
  113. }, errorData => {
  114. Common.processException(errorData);
  115. });
  116. }
  117. },
  118. /**
  119. * 查询Trace
  120. */
  121. uniqueById: function(traceCommentId) {
  122. return new Promise((resolve, reject) => {
  123. $.ajax({
  124. url: Common.getApiURL('TraceCommentResource/uniqueById'),
  125. type: 'get',
  126. dataType: 'json',
  127. contentType: 'application/json',
  128. data: {
  129. 'traceCommentId': traceCommentId,
  130. },
  131. beforeSend: function(request) {
  132. Common.addTokenToRequest(request);
  133. },
  134. success: function(data) {
  135. resolve(data);
  136. },
  137. error: function(XMLHttpRequest, textStatus, errorThrown) {
  138. reject(XMLHttpRequest);
  139. },
  140. });
  141. });
  142. },
  143. //----------文件------------
  144. /**
  145. * 删除文件
  146. * @param {String} item 文件Name
  147. */
  148. removeFile: function(index) {
  149. var _self = this;
  150. _self.files.splice(index, 1);
  151. },
  152. /**
  153. * 选择文件发生改变
  154. * @param {[type]} e [description]
  155. * @return {[type]} [description]
  156. */
  157. onFileChanges: function(e) {
  158. var files = e.target.files || e.dataTransfer.files;
  159. if (!files.length)
  160. return;
  161. this.uploadFile(files[0]);
  162. },
  163. /**
  164. * 上传文件
  165. * @param {File} selectedFile 选择的文件
  166. */
  167. uploadFile: function(selectedFile) {
  168. var _self = this;
  169. _self.showUploadDiv = false;
  170. if (selectedFile == undefined) {
  171. return;
  172. }
  173. if (selectedFile.size != undefined && selectedFile.size != null) {
  174. if ((selectedFile.size / 1024) <= (1024 * 4)) {
  175. var formData = new FormData();
  176. formData.append('files', selectedFile);
  177. formData.append('className', _self.className);
  178. _self.loading=true;
  179. $.ajax({
  180. url: Common.getApiURL('file/classFileUpload'),
  181. type: 'post',
  182. beforeSend: function(request) {
  183. Common.addTokenToRequest(request);
  184. },
  185. data: formData,
  186. contentType: false,
  187. processData: false,
  188. success: function(data) {
  189. _self.loading=false;
  190. if (data != 'error') {
  191. var fileName = data.substring(data.indexOf(':') + 1);
  192. _self.files.push(fileName);
  193. }
  194. },
  195. error: function(XMLHttpRequest, textStatus, errorThrown) {
  196. _self.loading=false;
  197. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  198. },
  199. });
  200. } else {
  201. Notify.error('提示', '文件大小不能超过4M!');
  202. }
  203. } else {
  204. Notify.error('提示', '上传的文件为空!');
  205. }
  206. },
  207. /**
  208. * 获取文件地址
  209. * @param {String} item 图片名称
  210. * @return {String} 图片URL地址
  211. */
  212. getFileSrc: function(item) {
  213. var _self = this;
  214. if (item != undefined && item != null) {
  215. return Common.getResourceUrl('file', _self.className, item);
  216. } else {
  217. return '';
  218. }
  219. },
  220. /**
  221. * 下载文件
  222. * @param {String} fileName 文件名
  223. * @return {void}
  224. */
  225. download: function(fileName) {
  226. var _self = this;
  227. DownloadService.fileDownload(_self.className, fileName);
  228. },
  229. //图片上传
  230. sendFile: function(file, editor, $editable) {
  231. var _self = this;
  232. UpladFile.photoCompress(file, {
  233. quality: 0.2,
  234. }, function(base64Codes) {
  235. var bl = UpladFile.convertBase64UrlToBlob(base64Codes);
  236. var rst = new FormData();
  237. rst.append('images', bl, 'file_' + Date.parse(new Date()) + '.jpg');
  238. rst.append('className', _self.className);
  239. $.ajax({
  240. url: Common.getApiURL('file/imageUpload'),
  241. type: 'post',
  242. data: rst,
  243. contentType: false,
  244. processData: false,
  245. beforeSend : function(request){
  246. Common.addTokenToRequest(request);
  247. },
  248. success: function(data) {
  249. if (data != 'error') {
  250. var imageName = data.substring(data.indexOf(':') + 1);
  251. $('#summernote').summernote('insertImage', Common.getResourceUrl('image', _self.className, imageName), 'image name');
  252. }
  253. },
  254. error: function() {
  255. Notify.error('提示', '上传失败!');
  256. return;
  257. },
  258. });
  259. return rst.file;
  260. });
  261. },
  262. /**
  263. * 修改并保存评论表数据
  264. * @author GuoZhiBo 20180302
  265. */
  266. photograph: function() {
  267. var _self = this;
  268. _self.traceComment.content = $('#summernote').summernote('code');
  269. if (_self.traceComment.content != '' && _self.traceComment.content != null) {
  270. _self.traceComment.attachments = _self.files.join(',');
  271. _self.loading=true;
  272. $.ajax({
  273. url: Common.getApiURL('TraceCommentResource/updateTraceComment'),
  274. type: 'post',
  275. contentType: 'application/json',
  276. beforeSend: function(request) {
  277. Common.addTokenToRequest(request);
  278. },
  279. data: JSON.stringify(_self.traceComment),
  280. success: function(data) {
  281. _self.loading=false;
  282. _self.back();
  283. },
  284. error: function(XMLHttpRequest, textStatus, errorThrown) {
  285. _self.loading=false;
  286. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  287. },
  288. });
  289. } else {
  290. Notify.error('提示', '请填写评论内容!');
  291. }
  292. },
  293. back: function() {
  294. var _self = this;
  295. history.back();
  296. },
  297. },
  298. };
  299. </script>
  300. <style scoped>
  301. .mui-divs3 {
  302. margin-top: 10px;
  303. }
  304. .file-input {
  305. width: 0.1px;
  306. height: 0.1px;
  307. opacity: 0;
  308. overflow: hidden;
  309. position: absolute;
  310. z-index: -1;
  311. }
  312. .badge {
  313. cursor: pointer;
  314. background-color: #428bca;
  315. color: white;
  316. }
  317. </style>