post.js 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. myApp.controller("postlist", ["$scope", "$http", "NgTableParams", "$timeout", function ($scope, $http, NgTableParams, $timeout) {
  2. window.hub.stop();
  3. $scope.loading();
  4. var self = this;
  5. self.stats = [];
  6. self.data = {};
  7. $scope.kw = "";
  8. $scope.orderby = 1;
  9. $scope.paginationConf = {
  10. currentPage: 1,
  11. //totalItems: $scope.total,
  12. itemsPerPage: 10,
  13. pagesLength: 25,
  14. perPageOptions: [1, 5, 10, 15, 20, 30, 40, 50, 100, 200],
  15. rememberPerPage: 'perPageItems',
  16. onChange: function() {
  17. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  18. }
  19. };
  20. $('.orderby').dropdown('set value', $scope.orderby);
  21. $('.orderby').dropdown({
  22. allowAdditions: false,
  23. onChange: function (value) {
  24. $scope.orderby = value;
  25. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  26. }
  27. });
  28. this.GetPageData = function (page, size) {
  29. $scope.loading();
  30. $http.post("/post/getpagedata", {
  31. page,
  32. size,
  33. kw: $scope.kw,
  34. orderby:$scope.orderby
  35. }).then(function(res) {
  36. //$scope.paginationConf.currentPage = page;
  37. $scope.paginationConf.totalItems = res.data.TotalCount;
  38. $("div[ng-table-pagination]").remove();
  39. self.tableParams = new NgTableParams({
  40. count: 50000
  41. }, {
  42. filterDelay: 0,
  43. dataset: res.data.Data
  44. });
  45. self.data = res.data.Data;
  46. Enumerable.From(res.data.Data).Select(e => e.Status).Distinct().ToArray().map(function(item, index, array) {
  47. self.stats.push({
  48. id: item,
  49. title: item
  50. });
  51. });
  52. self.stats = Enumerable.From(self.stats).Distinct().ToArray();
  53. $scope.loadingDone();
  54. });
  55. }
  56. self.del = function(row) {
  57. swal({
  58. title: "确认删除这篇文章吗?",
  59. text: row.Title,
  60. showCancelButton: true,
  61. confirmButtonColor: "#DD6B55",
  62. confirmButtonText: "确定",
  63. cancelButtonText: "取消",
  64. showLoaderOnConfirm: true,
  65. animation: true,
  66. allowOutsideClick: false
  67. }).then(function() {
  68. $scope.request("/post/delete", {
  69. id: row.Id
  70. }, function(data) {
  71. window.notie.alert({
  72. type: 1,
  73. text: data.Message,
  74. time: 4
  75. });
  76. });
  77. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  78. }, function() {
  79. }).catch(swal.noop);
  80. }
  81. self.truncate = function(row) {
  82. swal({
  83. title: "确认要彻底删除这篇文章吗?",
  84. text: row.Title,
  85. showCancelButton: true,
  86. confirmButtonColor: "#DD6B55",
  87. confirmButtonText: "确定",
  88. cancelButtonText: "取消",
  89. showLoaderOnConfirm: true,
  90. animation: true,
  91. allowOutsideClick: false
  92. }).then(function() {
  93. $scope.request("/post/truncate", {
  94. id: row.Id
  95. }, function(data) {
  96. window.notie.alert({
  97. type: 1,
  98. text: data.Message,
  99. time: 4
  100. });
  101. });
  102. _.remove(self.tableParams.settings().dataset, function(item) {
  103. return row === item;
  104. });
  105. self.tableParams.reload().then(function(data) {
  106. if (data.length === 0 && self.tableParams.total() > 0) {
  107. self.tableParams.page(self.tableParams.page() - 1);
  108. self.tableParams.reload();
  109. }
  110. });
  111. }, function() {
  112. }).catch(swal.noop);
  113. }
  114. self.pass = function(row) {
  115. $scope.request("/post/pass", row, function(data) {
  116. window.notie.alert({
  117. type: 1,
  118. text: data.Message,
  119. time: 4
  120. });
  121. self.stats = [];
  122. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  123. });
  124. }
  125. self.restore = function(row) {
  126. $scope.request("/post/restore", {
  127. id: row.Id
  128. }, function(data) {
  129. window.notie.alert({
  130. type: 1,
  131. text: data.Message,
  132. time: 4
  133. });
  134. self.stats = [];
  135. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  136. });
  137. }
  138. self.fixtop = function(id) {
  139. $scope.request("/post/Fixtop", {
  140. id: id
  141. }, function(data) {
  142. window.notie.alert({
  143. type: 1,
  144. text: data.Message,
  145. time: 4
  146. });
  147. self.stats = [];
  148. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  149. });
  150. }
  151. var _timeout;
  152. $scope.search = function (kw) {
  153. if (_timeout) {
  154. $timeout.cancel(_timeout);
  155. }
  156. _timeout = $timeout(function () {
  157. $scope.kw = kw;
  158. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  159. _timeout = null;
  160. }, 500);
  161. }
  162. $scope.loadingDone();
  163. $scope.toggleDisableComment= function(row) {
  164. $scope.request("/post/DisableComment", {
  165. id: row.Id
  166. }, function(data) {
  167. window.notie.alert({
  168. type: 1,
  169. text: data.Message,
  170. time: 4
  171. });
  172. });
  173. }
  174. }]);
  175. myApp.controller("writeblog", ["$scope", "$http", "$timeout", function ($scope, $http, $timeout) {
  176. window.hub.stop();
  177. clearInterval(window.interval);
  178. $scope.post = {
  179. Title: "",
  180. schedule: false,
  181. Content: "",
  182. CategoryId: 1,
  183. Label: "",
  184. Seminars: "",
  185. Keyword:""
  186. };
  187. $scope.loading();
  188. $scope.post.Author = $scope.user.NickName || $scope.user.Username;
  189. $scope.post.Email = $scope.user.Email;
  190. $scope.getCategory = function () {
  191. $scope.loading();
  192. $http.post("/category/getcategories", null).then(function (res) {
  193. $scope.loadingDone();
  194. var data = res.data;
  195. if (data.Success) {
  196. $scope.cat = data.Data;
  197. $('.ui.dropdown.category').dropdown({
  198. onChange: function (value) {
  199. $scope.post.CategoryId = value;
  200. },
  201. message: {
  202. maxSelections: '最多选择 {maxCount} 项',
  203. noResults: '无搜索结果!'
  204. }
  205. });
  206. } else {
  207. window.notie.alert({
  208. type: 3,
  209. text: '获取文章分类失败!',
  210. time: 4
  211. });
  212. }
  213. });
  214. }
  215. $scope.getCategory();
  216. $scope.request("/post/gettag", null, function(res) {
  217. $scope.Tags = res.Data;
  218. $('.ui.dropdown.tags').dropdown({
  219. allowAdditions: true,
  220. maxSelections: 5,
  221. message: {
  222. maxSelections: '最多选择 {maxCount} 项'
  223. },
  224. onChange: function(value) {
  225. $scope.post.Label = value;
  226. }
  227. });
  228. });
  229. $scope.request("/seminar/getall", null, function(res) {
  230. $scope.Seminars = res.Data;
  231. $('.ui.dropdown.seminar').dropdown({
  232. allowAdditions: false,
  233. onChange: function(value) {
  234. $scope.post.Seminars = value;
  235. }
  236. });
  237. $timeout(function () {
  238. $('.ui.dropdown.category').dropdown("set selected", [1]);
  239. }, 100);
  240. });
  241. $('.ui.dropdown.keyword').dropdown({
  242. allowAdditions: true,
  243. onChange: function(value) {
  244. $scope.post.Keyword = value;
  245. }
  246. });
  247. //上传Word文档
  248. $scope.upload = function() {
  249. $scope.loading();
  250. $("#docform").ajaxSubmit({
  251. url: "/Upload/UploadWord",
  252. type: "post",
  253. success: function(data) {
  254. $scope.loadingDone();
  255. console.log(data);
  256. if (data.Success) {
  257. window.notie.alert({
  258. type: 1,
  259. text: '文档上传成功!',
  260. time: 2
  261. });
  262. $scope.$apply(function() {
  263. $scope.post.Content = data.Data.Content;
  264. $scope.post.IsWordDocument = true;
  265. $scope.post.ResourceName = data.Data.ResourceName;
  266. $scope.post.Title = data.Data.Title;
  267. });
  268. layer.closeAll();
  269. } else {
  270. window.notie.alert({
  271. type: 3,
  272. text: data.Message,
  273. time: 4
  274. });
  275. }
  276. }
  277. });
  278. $scope.selectFile = false;
  279. }
  280. //文件上传
  281. $scope.showupload = function() {
  282. layui.use("layer", function() {
  283. var layer = layui.layer;
  284. layer.open({
  285. type: 1,
  286. title: '上传Word文档',
  287. area: ['420px', '150px'], //宽高
  288. content: $("#docfile")
  289. });
  290. });
  291. }
  292. //异步提交表单开始
  293. $scope.submit = function(post) {
  294. $scope.loading();
  295. if (!post.Label) {
  296. post.Label = null;
  297. }
  298. if (post.Title.trim().length <= 2 || post.Title.trim().length > 128) {
  299. window.notie.alert({
  300. type: 3,
  301. text: '文章标题必须在2到128个字符以内!',
  302. time: 4
  303. });
  304. $scope.loadingDone();
  305. return;
  306. }
  307. $http.post("/Post/write", post).then(function(res) {
  308. var data = res.data;
  309. $scope.loadingDone();
  310. if (data.Success) {
  311. window.notie.alert({
  312. type: 1,
  313. text: data.Message,
  314. time: 4
  315. });
  316. $scope.post.Content = "";
  317. $scope.post.Title = "";
  318. $scope.post.IsWordDocument = false;
  319. $scope.post.ResourceName = "";
  320. clearInterval(window.interval);
  321. localStorage.removeItem("write-post-draft");
  322. } else {
  323. window.notie.alert({
  324. type: 3,
  325. text: data.Message,
  326. time: 4
  327. });
  328. }
  329. });
  330. }
  331. //异步提交表单结束
  332. $scope.Scheduled= function() {
  333. $scope.post.schedule = !$scope.post.schedule;
  334. $timeout(function () {
  335. $('#timespan').jeDate({
  336. isinitVal: true,
  337. festival: true,
  338. isTime: true,
  339. ishmsVal: true,
  340. format: 'YYYY-MM-DD hh:mm:ss',
  341. minDate: new Date().Format("yyyy-MM-dd 00:00:00"),
  342. maxDate: '2099-06-16 23:59:59',
  343. okfun: function (obj) {
  344. $(obj.elem).val(obj.val);
  345. $scope.post.timespan = obj.val;
  346. }
  347. });
  348. }, 0);
  349. }
  350. //检查草稿
  351. if (localStorage.getItem("write-post-draft")) {
  352. notie.confirm({
  353. text: "检查到上次有未提交的草稿,是否加载?",
  354. submitText: "确定",
  355. cancelText: "取消",
  356. position: "bottom",
  357. submitCallback: function () {
  358. $scope.post = JSON.parse(localStorage.getItem("write-post-draft"));
  359. $scope.$apply();
  360. $timeout(function () {
  361. $('.ui.dropdown.category').dropdown('set selected', [$scope.post.CategoryId]);
  362. $('.ui.dropdown.tags').dropdown('set selected', $scope.post.Label.split(','));
  363. $('.ui.dropdown.keyword').dropdown('set selected', $scope.post.Keyword.split(','));
  364. $('.ui.dropdown.seminar').dropdown('set selected', $scope.post.Seminars.split(','));
  365. }, 10);
  366. window.interval = setInterval(function () {
  367. localStorage.setItem("write-post-draft",JSON.stringify($scope.post));
  368. },5000);
  369. },
  370. cancelCallback: function() {
  371. window.interval = setInterval(function () {
  372. localStorage.setItem("write-post-draft",JSON.stringify($scope.post));
  373. },5000);
  374. }
  375. });
  376. } else {
  377. window.interval = setInterval(function () {
  378. localStorage.setItem("write-post-draft",JSON.stringify($scope.post));
  379. },5000);
  380. }
  381. }]);
  382. myApp.controller("postedit", ["$scope", "$http", "$location", "$timeout", function ($scope, $http, $location, $timeout) {
  383. window.hub.stop();
  384. $scope.id = $location.search()['id'];
  385. $scope.loading();
  386. $scope.notify = true;
  387. $scope.reserve = true;
  388. $scope.request("/post/get", {
  389. id: $scope.id
  390. }, function (data) {
  391. $scope.post = data.Data;
  392. $scope.request("/post/gettag", null, function (res) {
  393. $scope.Tags = res.Data;
  394. $('.ui.dropdown.tags').dropdown({
  395. allowAdditions: true,
  396. maxSelections: 5,
  397. message: {
  398. maxSelections: '最多选择 {maxCount} 项'
  399. },
  400. onChange: function (value) {
  401. $scope.post.Label = value;
  402. }
  403. });
  404. });
  405. $('.ui.dropdown.tags').dropdown('set value', $scope.post.Label);
  406. $scope.request("/seminar/getall", null, function (res) {
  407. $scope.Seminars = res.Data;
  408. $('.ui.dropdown.seminar').dropdown({
  409. allowAdditions: true,
  410. maxSelections: 5,
  411. message: {
  412. maxSelections: '最多选择 {maxCount} 项'
  413. },
  414. onChange: function (value) {
  415. $scope.post.Seminars = value;
  416. }
  417. });
  418. if ($scope.post.Seminars) {
  419. $timeout(function () {
  420. $('.ui.dropdown.seminar').dropdown('set selected', $scope.post.Seminars.split(','));
  421. }, 10);
  422. }
  423. });
  424. $scope.getCategory();
  425. $('.ui.dropdown.keyword').dropdown({
  426. allowAdditions: true,
  427. onChange: function(value) {
  428. $scope.post.Keyword = value;
  429. }
  430. });
  431. $('.ui.dropdown.keyword').dropdown('set selected', $scope.post.Keyword.split(','));
  432. });
  433. $scope.getCategory = function () {
  434. $scope.loading();
  435. $http.post("/category/getcategories", null).then(function (res) {
  436. $scope.loadingDone();
  437. var data = res.data;
  438. if (data.Success) {
  439. $scope.cat = data.Data;
  440. $('.ui.dropdown.category').dropdown({
  441. onChange: function (value) {
  442. $scope.post.CategoryId = value;
  443. },
  444. message: {
  445. maxSelections: '最多选择 {maxCount} 项',
  446. noResults: '无搜索结果!'
  447. }
  448. });
  449. $timeout(function () {
  450. $('.ui.dropdown.category').dropdown('set selected', [$scope.post.CategoryId]);
  451. }, 10);
  452. } else {
  453. window.notie.alert({
  454. type: 3,
  455. text: '获取文章分类失败!',
  456. time: 4
  457. });
  458. }
  459. });
  460. }
  461. //上传Word文档
  462. $scope.upload = function () {
  463. $scope.loading();
  464. $("#docform").ajaxSubmit({
  465. url: "/Upload/UploadWord",
  466. type: "post",
  467. success: function (data) {
  468. $scope.loadingDone();
  469. console.log(data);
  470. if (data.Success) {
  471. window.notie.alert({
  472. type: 1,
  473. text: '文档上传成功!',
  474. time: 2
  475. });
  476. $scope.$apply(function () {
  477. $scope.post.Content = data.Data.Content;
  478. $scope.post.IsWordDocument = true;
  479. $scope.post.ResourceName = data.Data.ResourceName;
  480. $scope.post.Title = data.Data.Title;
  481. });
  482. layer.closeAll();
  483. } else {
  484. window.notie.alert({
  485. type: 3,
  486. text: data.Message,
  487. time: 4
  488. });
  489. }
  490. }
  491. });
  492. $scope.selectFile = false;
  493. }
  494. //文件上传
  495. $scope.showupload = function () {
  496. layui.use("layer", function () {
  497. var layer = layui.layer;
  498. layer.open({
  499. type: 1,
  500. title: '上传Word文档',
  501. area: ['420px', '150px'], //宽高
  502. content: $("#docfile")
  503. });
  504. });
  505. }
  506. //异步提交表单开始
  507. $scope.submit = function (post) {
  508. $scope.loading();
  509. if (!post.Label) {
  510. post.Label = null;
  511. }
  512. if (post.Title.trim().length <= 2 || post.Title.trim().length > 128) {
  513. window.notie.alert({
  514. type: 3,
  515. text: '文章标题必须在2到128个字符以内!',
  516. time: 4
  517. });
  518. $scope.loadingDone();
  519. return;
  520. }
  521. if (post.Author.trim().length <= 0 || post.Author.trim().length > 20) {
  522. window.notie.alert({
  523. type: 3,
  524. text: '再怎么你也应该留个合理的名字吧,非主流的我可不喜欢!',
  525. time: 4
  526. });
  527. $scope.loadingDone();
  528. return;
  529. }
  530. if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
  531. .test(post.Email.trim())) {
  532. window.notie.alert({
  533. type: 3,
  534. text: '请输入正确的邮箱格式!',
  535. time: 4
  536. });
  537. $scope.loadingDone();
  538. return;
  539. }
  540. if (post.Content.length < 200 || post.Content.length > 1000000) {
  541. window.notie.alert({
  542. type: 3,
  543. text: '文章内容过短或者超长的,我都认为你是在制造垃圾!',
  544. time: 4
  545. });
  546. $scope.loadingDone();
  547. return;
  548. }
  549. post.notify = $scope.notify;
  550. post.reserve = $scope.reserve;
  551. $http.post("/Post/edit", post).then(function (res) {
  552. var data = res.data;
  553. $scope.loadingDone();
  554. if (data.Success) {
  555. window.notie.alert({
  556. type: 1,
  557. text: data.Message,
  558. time: 4
  559. });
  560. $scope.post = data.Data;
  561. clearInterval(window.interval);
  562. localStorage.removeItem("post-draft-"+$scope.id);
  563. } else {
  564. window.notie.alert({
  565. type: 3,
  566. text: data.Message,
  567. time: 4
  568. });
  569. }
  570. });
  571. }
  572. //异步提交表单结束
  573. //检查草稿
  574. if (localStorage.getItem("post-draft-" + $scope.id)) {
  575. notie.confirm({
  576. text: "检查到上次有未提交的草稿,是否加载?",
  577. submitText: "确定",
  578. cancelText: "取消",
  579. position: "bottom",
  580. submitCallback: function () {
  581. $scope.post = JSON.parse(localStorage.getItem("post-draft-" + $scope.id));
  582. $scope.$apply();
  583. $timeout(function () {
  584. $('.ui.dropdown.category').dropdown('set selected', [$scope.post.CategoryId]);
  585. $('.ui.dropdown.tags').dropdown('set selected', $scope.post.Label.split(','));
  586. $('.ui.dropdown.keyword').dropdown('set selected', $scope.post.Keyword.split(','));
  587. $('.ui.dropdown.seminar').dropdown('set selected', $scope.post.Seminars.split(','));
  588. }, 10);
  589. window.interval = setInterval(function () {
  590. localStorage.setItem("post-draft-"+$scope.id,JSON.stringify($scope.post));
  591. },5000);
  592. },
  593. cancelCallback: function() {
  594. window.interval = setInterval(function () {
  595. localStorage.setItem("post-draft-"+$scope.id,JSON.stringify($scope.post));
  596. },5000);
  597. }
  598. });
  599. } else {
  600. window.interval = setInterval(function () {
  601. localStorage.setItem("post-draft-"+$scope.id,JSON.stringify($scope.post));
  602. },5000);
  603. }
  604. }]);
  605. myApp.controller("toppost", ["$scope", "$http", "$location", "$timeout", function ($scope, $http, $location, $timeout) {
  606. window.hub.stop();
  607. $scope.isAdd = true;
  608. $scope.allowUpload=false;
  609. $scope.loading();
  610. $scope.banner = {};
  611. $scope.getdata = function() {
  612. $scope.request("/banner/get", null, function(data) {
  613. $scope.banners = data.Data;
  614. });
  615. }
  616. $scope.getdata();
  617. $scope.remove = function(banner) {
  618. swal({
  619. title: '确定移除这个banner吗?',
  620. text: banner.Title,
  621. type: 'warning',
  622. showCancelButton: true,
  623. confirmButtonColor: '#3085d6',
  624. cancelButtonColor: '#d33',
  625. confirmButtonText: '确定',
  626. cancelButtonText: '取消'
  627. }).then(function(isConfirm) {
  628. if (isConfirm) {
  629. $scope.loading();
  630. $scope.request("/banner/delete/"+banner.Id, null, function(data) {
  631. swal(data.Message, null, 'success');
  632. $scope.getdata();
  633. });
  634. }
  635. }).catch(swal.noop);
  636. }
  637. $scope.add = function() {
  638. $scope.banner = {};
  639. $scope.isAdd = true;
  640. $scope.allowUpload=false;
  641. layer.open({
  642. type: 1,
  643. zIndex: 20,
  644. title: '设置头图页文章',
  645. area: (window.screen.width > 650 ? 650 : window.screen.width) + 'px',// '340px'], //宽高
  646. content: $("#modal"),
  647. cancel: function(index, layero) {
  648. setTimeout(function() {
  649. $("#modal").css("display", "none");
  650. }, 500);
  651. return true;
  652. }
  653. });
  654. }
  655. $scope.edit = function (item) {
  656. $scope.banner = item;
  657. $scope.isAdd = false;
  658. $scope.allowUpload=false;
  659. layer.open({
  660. type: 1,
  661. zIndex: 20,
  662. title: '设置头图页文章',
  663. area: (window.screen.width > 650 ? 650 : window.screen.width) + 'px',// '340px'], //宽高
  664. content: $("#modal"),
  665. cancel: function(index, layero) {
  666. setTimeout(function() {
  667. $("#modal").css("display", "none");
  668. }, 500);
  669. return true;
  670. }
  671. });
  672. }
  673. $scope.closeAll= function() {
  674. layer.closeAll();
  675. setTimeout(function() {
  676. $("#modal").css("display", "none");
  677. }, 500);
  678. }
  679. $scope.submit = function(banner) {
  680. if ($scope.isAdd) {
  681. banner.Id = 0;
  682. }
  683. $scope.request("/banner/save", banner, function(data) {
  684. //Custombox.close();
  685. $scope.closeAll();
  686. window.notie.alert({
  687. type: 1,
  688. text: data.Message,
  689. time: 4
  690. });
  691. $scope.getdata();
  692. $scope.banner.ImageUrl = "";
  693. $scope.banner.Description = "";
  694. });
  695. }
  696. $scope.uploadImage = function() {
  697. $scope.loading();
  698. $("#coverform").ajaxSubmit({
  699. url: "/Upload",
  700. type: "post",
  701. success: function(data) {
  702. $scope.loadingDone();
  703. document.getElementById("coverform").reset();
  704. $scope.$apply(function () {
  705.  $scope.allowUpload=false;
  706. $scope.banner.ImageUrl = data.Data;
  707. });
  708. }
  709. });
  710. };
  711. $scope.upload = function() {
  712. $scope.allowUpload=true;
  713. }
  714. }]);
  715. myApp.controller("category", ["$scope", "$http", "NgTableParams", function ($scope, $http, NgTableParams) {
  716. window.hub.stop();
  717. var self = this;
  718. var cats = [];
  719. self.data = {};
  720. this.load = function() {
  721. $scope.request("/category/GetCategories", null, function(res) {
  722. self.tableParams = new NgTableParams({}, {
  723. filterDelay: 0,
  724. dataset: res.Data
  725. });
  726. cats = res.Data;
  727. });
  728. }
  729. self.load();
  730. self.del = function(row) {
  731. var select = {};
  732. Enumerable.From(cats).Where(e => e.Name != row.Name).Select(e => {
  733. return {
  734. id: e.Id,
  735. name: e.Name
  736. }
  737. }).Distinct().ToArray().map(function(item, index, array) {
  738. select[item.id] = item.name;
  739. });
  740. swal({
  741. title: '确定删除这个分类吗?',
  742. text: "删除后将该分类下的所有文章移动到:",
  743. input: 'select',
  744. inputOptions: select,
  745. inputPlaceholder: '请选择分类',
  746. showCancelButton: true,
  747. confirmButtonColor: "#DD6B55",
  748. confirmButtonText: "确定",
  749. cancelButtonText: "取消",
  750. inputValidator: function(value) {
  751. return new Promise(function(resolve, reject) {
  752. if (value == '') {
  753. reject('请选择一个分类');
  754. } else {
  755. resolve();
  756. }
  757. });
  758. }
  759. }).then(function(result) {
  760. if (result) {
  761. if (row.Id == 1) {
  762. swal({
  763. type: 'error',
  764. html: "默认分类不能被删除!"
  765. });
  766. } else {
  767. $scope.request("/category/delete", {
  768. id: row.Id,
  769. cid:result
  770. }, function(data) {
  771. swal({
  772. type: 'success',
  773. html: data.Message
  774. });
  775. });
  776. _.remove(self.tableParams.settings().dataset, function(item) {
  777. return row === item;
  778. });
  779. self.tableParams.reload().then(function(data) {
  780. if (data.length === 0 && self.tableParams.total() > 0) {
  781. self.tableParams.page(self.tableParams.page() - 1);
  782. self.tableParams.reload();
  783. }
  784. });
  785. }
  786. }
  787. }).catch(swal.noop);
  788. }
  789. self.edit = function (row) {
  790. swal({
  791. title: '修改分类',
  792. html:
  793. '<div class="input-group"><span class="input-group-addon">分类名称: </span><input id="name" type="text" class="form-control input-lg" autofocus placeholder="请输入新的分类名" value="'+row.Name+'"></div>' +
  794. '<div class="input-group"><span class="input-group-addon">分类描述: </span><input id="desc" type="text" class="form-control input-lg" placeholder="请输入分类描述" value="'+row.Description+'"></div>',
  795. showCloseButton: true,
  796. showCancelButton: true,
  797. confirmButtonColor: "#DD6B55",
  798. confirmButtonText: "确定",
  799. cancelButtonText: "取消",
  800. showLoaderOnConfirm: true,
  801. allowOutsideClick: false,
  802. preConfirm: function () {
  803. return new Promise(function (resolve, reject) {
  804. row.Name = $('#name').val();
  805. row.Description = $('#desc').val();
  806. $http.post("/category/edit", row).then(function (res) {
  807. if (res.data.Success) {
  808. resolve(res.data.Message);
  809. } else {
  810. reject(res.data.Message);
  811. }
  812. }, function (error) {
  813. reject("操作失败");
  814. });
  815. });
  816. }
  817. }).then(function (msg) {
  818. if (msg) {
  819. swal({
  820. type: 'success',
  821. html: msg
  822. });
  823. self.load();
  824. }
  825. }).catch(swal.noop);
  826. }
  827. self.add = function() {
  828. swal({
  829. title: '请输入分类名',
  830. input: 'text',
  831. inputPlaceholder: '请输入分类',
  832. showCancelButton: true,
  833. confirmButtonColor: "#DD6B55",
  834. confirmButtonText: "确定",
  835. cancelButtonText: "取消",
  836. inputValidator: function(value) {
  837. return new Promise(function(resolve, reject) {
  838. if (value) {
  839. resolve();
  840. } else {
  841. reject('分类名不能为空');
  842. }
  843. });
  844. }
  845. }).then(function(result) {
  846. if (result) {
  847. $scope.request("/category/add", {
  848. Name: result
  849. }, function(data) {
  850. swal({
  851. type: 'success',
  852. html: data.Message
  853. });
  854. self.load();
  855. });
  856. }
  857. }).catch(swal.noop);
  858. }
  859. }]);
  860. myApp.controller("postpending", ["$scope", "$http", "NgTableParams", "$timeout", function ($scope, $http, NgTableParams, $timeout) {
  861. window.hub.stop();
  862. var self = this;
  863. $scope.loading();
  864. $scope.kw = "";
  865. $scope.orderby = 1;
  866. $scope.paginationConf = {
  867. currentPage: $scope.currentPage ? $scope.currentPage : 1,
  868. //totalItems: $scope.total,
  869. itemsPerPage: 10,
  870. pagesLength: 25,
  871. perPageOptions: [1, 5, 10, 15, 20, 30, 40, 50, 100, 200],
  872. rememberPerPage: 'perPageItems',
  873. onChange: function() {
  874. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  875. }
  876. };
  877. this.GetPageData = function(page, size) {
  878. $scope.loading();
  879. $http.post("/post/GetPending", {
  880. page,
  881. size,
  882. search:$scope.kw
  883. }).then(function(res) {
  884. $scope.paginationConf.currentPage = page;
  885. $scope.paginationConf.totalItems = res.data.TotalCount;
  886. $("div[ng-table-pagination]").remove();
  887. self.tableParams = new NgTableParams({
  888. count: 50000
  889. }, {
  890. filterDelay: 0,
  891. dataset: res.data.Data
  892. });
  893. $scope.loadingDone();
  894. });
  895. };
  896. self.del = function(row) {
  897. swal({
  898. title: "确认删除这篇文章吗?",
  899. text: row.Title,
  900. showCancelButton: true,
  901. confirmButtonColor: "#DD6B55",
  902. confirmButtonText: "确定",
  903. cancelButtonText: "取消",
  904. showLoaderOnConfirm: true,
  905. animation: true,
  906. allowOutsideClick: false
  907. }).then(function() {
  908. $scope.request("/post/delete", {
  909. id: row.Id
  910. }, function(data) {
  911. window.notie.alert({
  912. type: 1,
  913. text: data.Message,
  914. time: 4
  915. });
  916. });
  917. _.remove(self.tableParams.settings().dataset, function(item) {
  918. return row === item;
  919. });
  920. self.tableParams.reload().then(function(data) {
  921. if (data.length === 0 && self.tableParams.total() > 0) {
  922. self.tableParams.page(self.tableParams.page() - 1);
  923. self.tableParams.reload();
  924. }
  925. });
  926. }, function() {
  927. }).catch(swal.noop);
  928. }
  929. self.pass = function(row) {
  930. $scope.request("/post/pass", row, function(data) {
  931. window.notie.alert({
  932. type: 1,
  933. text: data.Message,
  934. time: 4
  935. });
  936. self.stats = [];
  937. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  938. });
  939. }
  940. var _timeout;
  941. $scope.search = function (kw) {
  942. if (_timeout) {
  943. $timeout.cancel(_timeout);
  944. }
  945. _timeout = $timeout(function () {
  946. $scope.kw = kw;
  947. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage, $scope.kw);
  948. _timeout = null;
  949. }, 500);
  950. }
  951. $scope.loadingDone();
  952. }]);
  953. myApp.controller("share", ["$scope", "$http", "NgTableParams", function ($scope, $http, NgTableParams) {
  954. window.hub.stop();
  955. var self = this;
  956. var shares = [];
  957. self.data = {};
  958. this.load = function() {
  959. $scope.request("/share", null, function(res) {
  960. self.tableParams = new NgTableParams({}, {
  961. filterDelay: 0,
  962. dataset: res.Data
  963. });
  964. shares = res.Data;
  965. });
  966. }
  967. self.load();
  968. $scope.closeAll = function() {
  969. layer.closeAll();
  970. setTimeout(function() {
  971. $("#modal").css("display", "none");
  972. }, 500);
  973. }
  974. $scope.submit = function (share) {
  975. if (share.Id) {
  976. //修改
  977. $scope.request("/share/update", share, function (data) {
  978. swal(data.Message, null, 'info');
  979. $scope.share = {};
  980. $scope.closeAll();
  981. self.load();
  982. });
  983. }else {
  984. $scope.request("/share/add", share, function (data) {
  985. window.notie.alert({
  986. type: 1,
  987. text: data.Message,
  988. time: 3
  989. });
  990. $scope.share = {};
  991. $scope.closeAll();
  992. self.load();
  993. });
  994. }
  995. }
  996. self.del = function(row) {
  997. swal({
  998. title: "确认删除这个分享吗?",
  999. text: row.Title,
  1000. showCancelButton: true,
  1001. showCloseButton: true,
  1002. confirmButtonColor: "#DD6B55",
  1003. confirmButtonText: "确定",
  1004. cancelButtonText: "取消",
  1005. showLoaderOnConfirm: true,
  1006. animation: true,
  1007. allowOutsideClick: false
  1008. }).then(function() {
  1009. $scope.request("/share/remove", {
  1010. id: row.Id
  1011. }, function(data) {
  1012. window.notie.alert({
  1013. type: 1,
  1014. text: data.Message,
  1015. time: 4
  1016. });
  1017. self.load();
  1018. });
  1019. }, function() {
  1020. }).catch(swal.noop);
  1021. }
  1022. self.edit = function (row) {
  1023. layer.open({
  1024. type: 1,
  1025. zIndex: 20,
  1026. title: '修改快速分享',
  1027. area: (window.screen.width > 600 ? 600 : window.screen.width) + 'px',
  1028. content: $("#modal"),
  1029. success: function(layero, index) {
  1030. $scope.share = row;
  1031. },
  1032. end: function() {
  1033. $("#modal").css("display", "none");
  1034. }
  1035. });
  1036. }
  1037. self.add = function() {
  1038. layer.open({
  1039. type: 1,
  1040. zIndex: 20,
  1041. title: '添加快速分享',
  1042. area: (window.screen.width > 600 ? 600 : window.screen.width) + 'px',
  1043. content: $("#modal"),
  1044. success: function(layero, index) {
  1045. $scope.share = {};
  1046. },
  1047. end: function() {
  1048. $("#modal").css("display", "none");
  1049. }
  1050. });
  1051. }
  1052. }]);