topic.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. $(function () {
  2. $("#jqGrid").Grid({
  3. url: '../topic/list',
  4. rownumWidth:60,
  5. colModel: [
  6. {label: 'id', name: 'id', index: 'id', key: true, hidden: true},
  7. {label: '活动主题', name: 'title', index: 'title', width: 80},
  8. {label: '活动内容', name: 'content', index: 'content', width: 80, hidden: true},
  9. {
  10. label: '图像', name: 'avatar', index: 'avatar', width: 80, formatter: function (value) {
  11. return transImg(value);
  12. }
  13. },
  14. {
  15. label: '活动条例图片', name: 'itemPicUrl', index: 'item_pic_url', width: 80, formatter: function (value) {
  16. return transImg(value);
  17. }
  18. },
  19. {label: '子标题', name: 'subtitle', index: 'subtitle', width: 80},
  20. {label: '活动类别', name: 'topicCategoryId', index: 'topic_category_id', width: 80},
  21. {label: '活动价格', name: 'priceInfo', index: 'price_info', width: 80},
  22. {label: 'readCount', name: 'readCount', index: 'read_count', width: 80},
  23. {
  24. label: '场景图片', name: 'scenePicUrl', index: 'scene_pic_url', width: 80, formatter: function (value) {
  25. return transImg(value);
  26. }
  27. },
  28. {label: '活动模板Id', name: 'topicTemplateId', index: 'topic_template_id', width: 80},
  29. {label: '活动标签Id', name: 'topicTagId', index: 'topic_tag_id', width: 80}]
  30. });
  31. $('#content').editable({
  32. inlineMode: false,
  33. alwaysBlank: true,
  34. height: 'auto', //高度
  35. language: "zh_cn",
  36. minHeight: '200px',
  37. spellcheck: false,
  38. plainPaste: true,
  39. enableScript: false,
  40. imageButtons: ["floatImageLeft", "floatImageNone", "floatImageRight", "linkImage", "replaceImage", "removeImage"],
  41. allowedImageTypes: ["jpeg", "jpg", "png", "gif"],
  42. imageUploadURL: '../sys/oss/upload',//上传到本地服务器
  43. imageUploadParams: {id: "edit"},
  44. // imageManagerDeleteURL: '../sys/oss/delete',//删除图片(有问题)
  45. imagesLoadURL: '../sys/oss/queryAll'//管理图片
  46. });
  47. });
  48. var vm = new Vue({
  49. el: '#rrapp',
  50. data: {
  51. showList: true,
  52. title: null,
  53. topic: {avatar: '', itemPicUrl: '', scenePicUrl: ''},
  54. ruleValidate: {
  55. title: [
  56. {required: true, message: '活动主题不能为空', trigger: 'blur'}
  57. ]
  58. },
  59. q: {
  60. title: ''
  61. }
  62. },
  63. methods: {
  64. query: function () {
  65. vm.reload();
  66. },
  67. add: function () {
  68. vm.showList = false;
  69. vm.title = "新增";
  70. vm.topic = {avatar: '', itemPicUrl: '', scenePicUrl: ''};
  71. $('#content').editable('setHTML', '');
  72. },
  73. update: function (event) {
  74. var id = getSelectedRow("#jqGrid");
  75. if (id == null) {
  76. return;
  77. }
  78. vm.showList = false;
  79. vm.title = "修改";
  80. vm.getInfo(id)
  81. },
  82. saveOrUpdate: function (event) {
  83. var url = vm.topic.id == null ? "../topic/save" : "../topic/update";
  84. //编辑器内容
  85. vm.topic.content = $('#content').editable('getHTML');
  86. Ajax.request({
  87. type: "POST",
  88. url: url,
  89. contentType: "application/json",
  90. params: JSON.stringify(vm.topic),
  91. successCallback: function (r) {
  92. alert('操作成功', function (index) {
  93. vm.reload();
  94. });
  95. }
  96. });
  97. },
  98. del: function (event) {
  99. var ids = getSelectedRows("#jqGrid");
  100. if (ids == null) {
  101. return;
  102. }
  103. confirm('确定要删除选中的记录?', function () {
  104. Ajax.request({
  105. type: "POST",
  106. url: "../topic/delete",
  107. contentType: "application/json",
  108. params: JSON.stringify(ids),
  109. successCallback: function (r) {
  110. alert('操作成功', function (index) {
  111. vm.reload();
  112. });
  113. }
  114. });
  115. });
  116. },
  117. getInfo: function (id) {
  118. Ajax.request({
  119. url: "../topic/info/" + id,
  120. async: true,
  121. successCallback: function (r) {
  122. vm.topic = r.topic;
  123. $('#content').editable('setHTML', vm.topic.content);
  124. }
  125. });
  126. },
  127. reload: function (event) {
  128. vm.showList = true;
  129. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  130. $("#jqGrid").jqGrid('setGridParam', {
  131. postData: {'title': vm.q.title},
  132. page: page
  133. }).trigger("reloadGrid");
  134. vm.handleReset('formValidate');
  135. },
  136. handleSuccessAvatar: function (res, file) {
  137. vm.topic.avatar = file.response.url;
  138. },
  139. handleSuccessItemPicUrl: function (res, file) {
  140. vm.topic.itemPicUrl = file.response.url;
  141. },
  142. handleSuccessScenePicUrl: function (res, file) {
  143. vm.topic.scenePicUrl = file.response.url;
  144. },
  145. handleFormatError: function (file) {
  146. this.$Notice.warning({
  147. title: '文件格式不正确',
  148. desc: '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。'
  149. });
  150. },
  151. handleMaxSize: function (file) {
  152. this.$Notice.warning({
  153. title: '超出文件大小限制',
  154. desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
  155. });
  156. },
  157. eyeImageAvatar: function () {
  158. var url = vm.topic.avatar;
  159. eyeImage(url);
  160. },
  161. eyeImageItemPicUrl: function () {
  162. var url = vm.topic.itemPicUrl;
  163. eyeImage(url);
  164. },
  165. eyeImageScenePicUrl: function () {
  166. var url = vm.topic.scenePicUrl;
  167. eyeImage(url);
  168. },
  169. handleSubmit: function (name) {
  170. handleSubmitValidate(this, name, function () {
  171. vm.saveOrUpdate()
  172. });
  173. },
  174. handleReset: function (name) {
  175. handleResetForm(this, name);
  176. }
  177. }
  178. });