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