发表于: 2017-05-24 23:34:49

2 965




今天完成的事情:


1.修改上下线功能;通过判断status切换上下线的状态;

$scope.revisestatus=function (id,status) {
var revisestatus=confirm("确认修改id为:"+id+'的状态?');
   if (revisestatus==true){
       if (status==1){
            status=2;
       }else {
            status=1;
       }
       $http({
           method:'put',
           url:'/a/a/u/article/status',
           params:{
                id:id,
               status:status
           }
           }).then(function success(mes) {
           if (mes.data.code===0){
                   alert('修改成功');
                   $scope.aaa();
                   $state.go('home.list');
               }
          },function error(mes) {
       });
   }
};


2.删除功能;

$scope.deleteid=function (id) {
var deleteid=confirm("确认删除id为:"+id+'的所有数据?');
   if (deleteid==true){
$http({
method:'delete',
           url:"/a/a/u/article/"+id
       }).then(function success(res) {
if (res.data.code===0){ alert('删除成功');
               $state.go('home.list');
           }
},function error(res) {
});
       $scope.aaa();
   }
};


3.新增页面基本功能,表单验证还没有做;

var studentAdd=angular.module('myApp');
studentAdd.controller('AddCtrl',function ($scope, $http, $state,$upload) {
var editor = new wangEditor('content');
// 上传图片(举例)没整明白,先注释掉不用了
//    editor.config.uploadImgUrl = '/upload.php';
//    editor.config.uploadImgFileName = 'myFileName';
   editor.create();
//图片上传
   var imgPreview=document.getElementById('imgPreview');
   $scope.onFileSelect=function ($files) {
       for (var i = 0; i < $files.length; i++) {
           var file = $files[i];
           console.log(file);
           $scope.upload = $upload.upload({
               url: '/a/a/u/img/task',
               method: 'POST',
               file:file
           }).progress(function (evt) {
            
           }).success(function (data,status,headers,config) {
               $scope.imgName= data.data.url;
               imgPreview.innerHTML="<img src="+data.data.url+" >";
           }).error(function (data, status, headers, config) {
               
           })
}
};
         $scope.addsubmit=function () {
         $http({
           method:'post',
           url:'/a/a/u/article',
           params:{
               title:$scope.firmtitle,
               url:$scope.firmurl,
               type:$scope.firmType,
               img:$scope.imgName,
               status:$scope.firmStatus,
               content:$scope.content
           }
}).then(function success(res) {
if (res.data.code==0){
$state.go('home.list');
           }
},function error(res) {
console.log(res);
       });
   };
   $scope.addcancel=function () {
$state.go('home.list');
   };
})


明天计划做的事情:研究下编辑功能,编辑功能应该和新增功能差不多,差别应该就是在于编辑页面要把之前的数


据线渲染出来,然后在修改;


遇到的问题:


1.坦白承认错误:图片上传是抄的,只是把功能实现了,知道这么用可以,具体的图片上传是什么原


理,该怎么写其实不理解;


2.修改上下线功能这里有个坑;就是请求成功之后需要执行一下aaa()这个函数:不然页面上的上线或者草稿状


态是不改变的,其实这个时候请求已经成功了,数据也已经改变了,只是我们的页面还没有自动刷新,我们手动刷


新一下页面就会发现其实状态已经改变了;我们在发送请求成功之后执行下我们aaa()这个函数就可以自动刷新


了,aaa()这个函数是我之前请求列表页数据的方法;


收获:修改上下线功能;删除功能;新增功能基本实现了,感觉还是挺不错的,虽然图片上传是是抄的


但是知道怎么用了。



返回列表 返回列表
评论

    分享到