TraceCommentEdit.vue 9.1 KB

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