disclaimerCtrl.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. app.controller('EditorCtrl', ['$scope', '$http', '$timeout', '$state', '$stateParams', 'toaster', 'FileUploader', function ($scope, $http, $timeout, $state, $stateParams, toaster, FileUploader) {
  2. var agentId = $stateParams.agentId
  3. $scope.agentName = $stateParams.agentName
  4. if (!agentId) {
  5. history.back()
  6. toaster.pop("info", "提示", "查询id错误");
  7. return
  8. }
  9. var editor = new window.wangEditor('#wEditor1')
  10. editor.create()
  11. $http.get('/superadmin/getAgentDisclaimer', {
  12. params: {
  13. agentId: agentId
  14. }
  15. }).then(function (res) {
  16. var data = res.data
  17. var payload = data.payload
  18. editor.txt.html(payload.content)
  19. $scope.needDisclaimer = payload.needDisclaimer
  20. $scope.version = payload.version
  21. }).catch(function (data) {
  22. toaster.pop("error", "提示", "获取数据失败");
  23. });
  24. $scope.selectFile = function (){
  25. $('#htmlUp').trigger("click")
  26. }
  27. $scope.changeFile = function (files){
  28. if (files.length) {
  29. var file = files[0];
  30. var reader = new FileReader();
  31. // 文件不能大于1M
  32. if (file.size > 1000 * 1024) {
  33. toaster.pop("info", "提示", "文件不能大于1M,请重新选择");
  34. } else {
  35. reader.onload = function() {
  36. if(reader.result) {
  37. var text = reader.result
  38. editor.txt.html(text)
  39. $('#htmlUp').val('')// 置空
  40. }
  41. };
  42. reader.readAsText(file);
  43. }
  44. }
  45. }
  46. $scope.saveDisclaimer = function () {
  47. var html = editor.txt.html()
  48. $http.post('/superadmin/setAgentDisclaimer', {
  49. "needDisclaimer": $scope.needDisclaimer,
  50. "content": html,
  51. "version": $scope.version,
  52. "agentId": agentId
  53. }).then(function (res) {
  54. toaster.pop("success", "提示", "保存成功");
  55. }).catch(function (data) {
  56. toaster.pop("error", "提示", "获取数据失败");
  57. });
  58. }
  59. }]);