1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- app.controller('EditorCtrl', ['$scope', '$http', '$timeout', '$state', '$stateParams', 'toaster', 'FileUploader', function ($scope, $http, $timeout, $state, $stateParams, toaster, FileUploader) {
- var agentId = $stateParams.agentId
- $scope.agentName = $stateParams.agentName
- if (!agentId) {
- history.back()
- toaster.pop("info", "提示", "查询id错误");
- return
- }
- var editor = new window.wangEditor('#wEditor1')
- editor.create()
- $http.get('/superadmin/getAgentDisclaimer', {
- params: {
- agentId: agentId
- }
- }).then(function (res) {
- var data = res.data
- var payload = data.payload
- editor.txt.html(payload.content)
- $scope.needDisclaimer = payload.needDisclaimer
- $scope.version = payload.version
- }).catch(function (data) {
- toaster.pop("error", "提示", "获取数据失败");
- });
- $scope.selectFile = function (){
- $('#htmlUp').trigger("click")
- }
- $scope.changeFile = function (files){
- if (files.length) {
- var file = files[0];
- var reader = new FileReader();
- // 文件不能大于1M
- if (file.size > 1000 * 1024) {
- toaster.pop("info", "提示", "文件不能大于1M,请重新选择");
- } else {
- reader.onload = function() {
- if(reader.result) {
- var text = reader.result
- editor.txt.html(text)
- $('#htmlUp').val('')// 置空
- }
- };
- reader.readAsText(file);
- }
- }
- }
- $scope.saveDisclaimer = function () {
- var html = editor.txt.html()
- $http.post('/superadmin/setAgentDisclaimer', {
- "needDisclaimer": $scope.needDisclaimer,
- "content": html,
- "version": $scope.version,
- "agentId": agentId
- }).then(function (res) {
- toaster.pop("success", "提示", "保存成功");
- }).catch(function (data) {
- toaster.pop("error", "提示", "获取数据失败");
- });
- }
- }]);
|