Files
vczero.github.io/tuban/client-admin/build/main.min.js
T
2014-12-26 20:44:54 +08:00

2 lines
7.5 KiB
JavaScript

/*! tuban-admin 2014-12-26 */
var app=angular.module("app",["ui.router","ngCookies","ngGrid"]),SERVER_BASE_URL="http://123.57.39.116:6547/";app.run(["$rootScope",function(a){a.appName="图班网",a.desc="后台管理",a.author="鬼谣",a.email="wlhmyit@126.com"}]),app.constant("ServiceConfig",{user_login:SERVER_BASE_URL+"user/login",user_getAll:SERVER_BASE_URL+"user/getAll",user_updateTag:SERVER_BASE_URL+"user/updateTag",user_getUserByCondition:SERVER_BASE_URL+"user/getByCondition",user_delete:SERVER_BASE_URL+"user/delete",article_create:SERVER_BASE_URL+"article/create",weibo_getByCondition:SERVER_BASE_URL+"wei/getByCondition",weibo_set2null:SERVER_BASE_URL+"wei/set2null",email_findPassword:SERVER_BASE_URL+"email/findPassword"}),app.config(["$httpProvider",function(a){a.defaults.headers.post["Content-Type"]="application/x-www-form-urlencoded;charset=utf-8",a.defaults.headers.put["Content-Type"]="application/x-www-form-urlencoded;charset=utf-8",a.defaults.transformRequest=[function(a){var b=[];for(var c in a)b.push(c+"="+a[c]);return b.join("&")}]}]),app.config(["$stateProvider","$urlRouterProvider",function(a,b){b.otherwise("/"),a.state("login",{url:"/",views:{"":{templateUrl:"views/login.html",controller:"LoginController"}}}).state("index",{url:"/index",views:{"":{templateUrl:"views/index.html",controller:"MenuController"}}}).state("index.article",{url:"/article",views:{"":{templateUrl:"views/index.html",controller:"MenuController"},"list@index":{templateUrl:"views/article.html",controller:"ArticleController"}}}).state("index.weibo",{url:"/weibo",views:{"":{templateUrl:"views/index.html",controller:"MenuController"},"list@index":{templateUrl:"views/weibo.html",controller:"WeiboController"}}}).state("index.user",{url:"/user",views:{"":{templateUrl:"views/index.html",controller:"MenuController"},"list@index":{templateUrl:"views/user.html",controller:"UserController"}}}).state("index.email",{url:"/email",views:{"":{templateUrl:"views/index.html",controller:"MenuController"},"list@index":{templateUrl:"views/email.html",controller:"EmailController"}}})}]),app.service("MenuSelect",["$rootScope",function(a){return{setSelected:function(b){a.select_user="menu_unselect",a.select_article="menu_unselect",a.select_weibo="menu_unselect",a.select_email="menu_unselect",a.select_login="menu_unselect",b&&(a[b]="menu_select")}}}]),app.controller("LoginController",["$scope","$http","$rootScope","$cookieStore","$timeout","$location","ServiceConfig",function(a,b,c,d,e,f,g){a.login=function(){var c=a.email,h=a.password,i={email:c,password:h};b.post(g.user_login,i).success(function(a){if(a.status)d.put("user",a),f.path("/index/user");else{var b=window.innerWidth;Tip.setTip(250,(parseInt(b)-240)/2,null,null,260,80,"难倒你忘记了密码...",1),e(Tip.hideTip,3e3)}}).error(function(){var a=window.innerWidth;Tip.setTip(250,(parseInt(a)-240)/2,null,null,260,80,"服务君该回家养老了...",1),e(Tip.hideTip,3e3)})},a.goRegister=function(){f.path("/register")}}]),app.controller("ArticleController",["$scope","$rootScope","$timeout","$http","$cookieStore","ServiceConfig","MenuSelect",function(a,b,c,d,e,f,g){var h=e.get("user"),i=window.innerWidth;g.setSelected("select_article"),a.author="",a.submit=function(b,e,g,j,k){var l={token:h.token,title:b||"",author:e||"",link:g||"",ref:j||"",content:k||[]};d.post(f.article_create,l).success(function(b){b.status?(a.author="",a.title="",a.author="",a.ref="",a.link="",a.content="",Tip.setTip(250,(parseInt(i)-240)/2,null,null,260,80,"文章发表成功....",1),c(Tip.hideTip,3e3)):(Tip.setTip(250,(parseInt(i)-240)/2,null,null,260,80,"文章发表失败....",1),c(Tip.hideTip,3e3))})}}]),app.controller("MenuController",["$rootScope","$location",function(a,b){var c=b.path();switch(c){case"/index/user":a.select_user="menu_select";break;case"/index/article":a.select_article="menu_select";break;case"/index/weibo":a.select_weibo="menu_select";break;case"/index/qita":a.select_qita="menu_select";break;case"/index/login":a.select_login="menu_select"}}]),app.controller("UserController",["$scope","$rootScope","$timeout","$http","$cookieStore","ServiceConfig","MenuSelect",function(a,b,c,d,e,f,g){var h=e.get("user"),i=window.innerWidth;g.setSelected("select_user"),a.mySelections=[],a.filterOptions={filterText:"",useExternalFilter:!0},a.totalServerItems=0,a.pagingOptions={pageSizes:[10,15,30],pageSize:10,currentPage:1},a.setPagingData=function(b,c,d){var e=b.slice((c-1)*d,c*d);a.myData=e,a.totalServerItems=b.length,a.$$phase||a.$apply()},a.getPagedDataAsync=function(b,c){setTimeout(function(){d.get(f.user_getAll+"?token="+h.token).success(function(d){d.status&&a.setPagingData(d.items,c,b)})},100)},a.getPagedDataAsync(a.pagingOptions.pageSize,a.pagingOptions.currentPage),a.$watch("pagingOptions",function(b,c){b!==c&&b.currentPage!==c.currentPage&&a.getPagedDataAsync(a.pagingOptions.pageSize,a.pagingOptions.currentPage)},!0),a.$on("ngGridEventEndCellEdit",function(a){var b=a.targetScope.row.entity,e={userid:b.userid,token:h.token,tag:b.tag};d.post(f.user_updateTag,e).success(function(a){a.status||(Tip.setTip(250,(parseInt(i)-240)/2,null,null,260,80,"数据更新失败",1),c(Tip.hideTip,3e3))})}),a.removeRow=function(a){var b={token:h.token,userid:a.userid};console.log(f.user_delete),d.post(f.user_delete,b).success(function(a){a.status?(Tip.setTip(250,(parseInt(i)-240)/2,null,null,260,80,"删除成功......",1),c(Tip.hideTip,3e3)):(Tip.setTip(250,(parseInt(i)-240)/2,null,null,260,80,"删除失败......",1),c(Tip.hideTip,3e3))})},a.gridOptions={data:"myData",enablePaging:!0,showFooter:!0,enableCellEdit:!0,totalServerItems:"totalServerItems",pagingOptions:a.pagingOptions,multiSelect:!1,selectedItems:a.mySelections,columnDefs:[{field:"userid",displayName:"用户ID"},{field:"email",displayName:"邮箱"},{field:"tag",displayName:"角色"},{field:"nickname",displayName:"昵称"},{field:"realname",displayName:"真实姓名"},{field:"tel",displayName:"电话"},{field:"慎重操作",cellTemplate:'<button class="user_btn" ng-click="removeRow(row.entity)">删除</button>'}]},a.Search=function(b,c,e){if(13===b.keyCode||32===b.which){var g="?token="+h.token+"&",c=c||"default";switch(c){case"email":g=g+"email="+e;break;case"nickname":g=g+"nickname="+e;break;case"realname":g=g+"realname="+e;break;default:console.log(e),g=g+"email="+e}d.get(f.user_getUserByCondition+g).success(function(b){b.status&&(a.mySelections=b.items)})}}}]),app.controller("WeiboController",["$scope","$rootScope","$http","$cookieStore","$timeout","ServiceConfig","MenuSelect",function(a,b,c,d,e,f,g){var h=d.get("user"),i=window.innerWidth;g.setSelected("select_weibo"),a.email="",a.search=function(b,d,e,g){var h="";b&&(h="?email="+b),d&&(h="?nickname="+d),e&&(h="?realname="+e),g&&(h="?content="+g),c.get(f.weibo_getByCondition+h).success(function(b){a.weiboObj=JSON.stringify(b)})},a.modify=function(){var b={token:h.token,_id:JSON.parse(a.weiboObj)._id};c.post(f.weibo_set2null,b).success(function(a){a.status?(Tip.setTip(250,(parseInt(i)-240)/2,null,null,260,80,"微博置空成功....",1),e(Tip.hideTip,3e3)):(Tip.setTip(250,(parseInt(i)-240)/2,null,null,260,80,"微博置空失败....",1),e(Tip.hideTip,3e3))})}}]),app.controller("EmailController",["$scope","$rootScope","$http","$timeout","$cookieStore","ServiceConfig","MenuSelect",function(a,b,c,d,e,f,g){var h=e.get("user"),i=window.innerWidth;g.setSelected("select_email"),a.postEmail=function(a){var b={token:h.token,email:a};c.post(f.email_findPassword,b).success(function(a){a.status?(Tip.setTip(250,(parseInt(i)-240)/2,null,null,260,80,"邮件发送成功....",1),d(Tip.hideTip,3e3)):(Tip.setTip(250,(parseInt(i)-240)/2,null,null,260,80,"邮件发送失败....",1),d(Tip.hideTip,3e3))})}}]);