admin.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. //左边菜单栏目点击
  2. $(".layui-logo").click(function(){
  3. if($(".left-menu").css("display")=='block'){
  4. $(".left-menu").css("display","none");
  5. $(".layui-body,.layui-footer").css("left","0px");
  6. }else{
  7. $(".left-menu").css("display","block");
  8. $(".layui-body,.layui-footer").css("left","200px");
  9. }
  10. });
  11. function ToLink(url){
  12. $("iframe").attr('src',url);
  13. }
  14. /*iframe打开弹窗*/
  15. function LayerOpen(url){
  16. layer.open({
  17. type: 2,
  18. //title: '添加',
  19. shadeClose: true,
  20. shade: false,
  21. maxmin: true, //开启最大化最小化按钮
  22. area: ['893px', '600px'],
  23. content: url
  24. });
  25. }
  26. //弹出框
  27. function alert(data='操作成功~',url=''){
  28. //不作任何操作
  29. if(url==''){
  30. layer.open({
  31. title: '提示',
  32. content: data
  33. });
  34. //刷新
  35. }else if(url=='1' || url=='reload'){
  36. layer.open({
  37. title: '提示',
  38. content: data,
  39. yes: function(){
  40. location.reload();
  41. },cancel: function(){
  42. location.reload();
  43. }
  44. });
  45. //跳转
  46. }else{
  47. layer.open({
  48. title: '提示',
  49. content: data,
  50. yes: function(){
  51. location.href=url;
  52. },cancel: function(){
  53. location.href=url;
  54. }
  55. });
  56. }
  57. }
  58. /*修改状态*/
  59. function setstatus(url,id,status,type){
  60. if(type){
  61. layer.confirm('是否确认当前操作?', {icon: 3, title:'提示'}, function(index){
  62. $.post(url,{"id":id,"status":status},function(data){
  63. alert(data.msg,1);
  64. },'JSON');
  65. });
  66. }else{
  67. $.post(url,{"id":id,"status":status},function(data){
  68. alert(data.msg,1);
  69. },'JSON');
  70. }
  71. }
  72. /*表单提交*/
  73. function FormAjax(href, data='', table='table'){
  74. $.ajax({
  75. url: href,
  76. type: 'PUT',
  77. dataType:"json",
  78. data:data,
  79. success: function(res) {
  80. if(typeof(parent.table) != 'undefined'){
  81. parent.table.reload(table);
  82. }
  83. layer.alert(res.msg, function(){
  84. if(typeof(parent.table) != 'undefined'){
  85. parent.layer.closeAll();
  86. }else if(res.url !=''){
  87. location.href = res.url;
  88. }
  89. });
  90. }
  91. });
  92. return false;
  93. }
  94. /*初始化表单请求数据*/
  95. function FormGet( obj={} ){
  96. if(typeof (obj.href) == "undefined"){
  97. obj.href =location.href;
  98. }
  99. if(typeof (obj.id) == "undefined"){
  100. obj.id ="form";
  101. }
  102. $.get(obj.href,{},function(data){
  103. if(typeof (obj.inc) != "undefined" ){
  104. obj.inc(data);
  105. console.log(data);
  106. }
  107. form.val(obj.id, data);
  108. },'json');
  109. }
  110. /*删除数据*/
  111. function Delete(href, data='', obj, msg ='真的删除本条数据吗?'){
  112. layer.confirm(msg, function(index){
  113. $.ajax({
  114. url: href,
  115. type: 'delete',
  116. dataType:"json",
  117. data:data,
  118. success: function(res) {
  119. if(res.code=='1'){
  120. alert(res.msg);
  121. obj.del();
  122. layer.close(index);
  123. }else{
  124. alert(res.msg);
  125. }
  126. }
  127. });
  128. });
  129. return false;
  130. }
  131. /*修改状态*/
  132. function Status(href, data, tip='error',table='table'){
  133. $.ajax({
  134. url: href,
  135. type: 'PUT',
  136. dataType:"json",
  137. data:data,
  138. success: function(res) {
  139. if(res.code =='0'){
  140. alert(res.msg);
  141. }else{
  142. alert('状态修改成功~');
  143. }
  144. }
  145. });
  146. }
  147. var admin = {
  148. init : function(arr=[]){
  149. for ( i in arr ) {
  150. eval("this."+arr[i]+"()");
  151. }
  152. },
  153. aa : function(){
  154. alert('sadfd');
  155. },
  156. add : function(){
  157. form.on('submit(submit)', function(data){
  158. $.ajax({
  159. url: location.href,
  160. type: 'PUT',
  161. dataType:"json",
  162. data:data,
  163. success: function(res) {
  164. if(typeof(parent.table) != 'undefined'){
  165. parent.table.reload(table);
  166. }
  167. layer.alert(res.msg, function(){
  168. if(typeof(parent.table) != 'undefined'){
  169. parent.layer.closeAll();
  170. }else if(res.url !=''){
  171. location.href = res.url;
  172. }
  173. });
  174. },
  175. error: function(){
  176. alert("上传失败");
  177. }
  178. });
  179. return false;
  180. });
  181. },
  182. submit : function(){
  183. form.on('submit(submit)', function(data){
  184. $.ajax({
  185. url: location.href,
  186. type: 'PUT',
  187. dataType:"json",
  188. data:data.field,
  189. success: function(res) {
  190. if(typeof(parent.table) != 'undefined' ){
  191. parent.table.reload(table);
  192. }
  193. layer.alert(res.msg, function(){
  194. if(typeof(parent.table) != 'undefined'){
  195. parent.layer.closeAll();
  196. }else if(res.url !=''){
  197. location.href = res.url;
  198. }else{
  199. location.href = location.href;
  200. }
  201. });
  202. }
  203. });
  204. return false;
  205. });
  206. },
  207. //上传
  208. fileupload : function ( object={} ){
  209. if(typeof(object.elem) == 'undefined'){
  210. object.elem = '.fileupload';
  211. }
  212. if(typeof(object.url) == 'undefined'){
  213. object.url = '/admin.php/common/fileupload.html';
  214. }
  215. if(typeof(object.field) == 'undefined'){
  216. object.field = 'file';
  217. }
  218. console.log(object);
  219. upload.render({
  220. elem: object.elem //绑定元素
  221. ,url: object.url //上传接口
  222. ,before: function(obj){ //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
  223. layer.load(); //上传loading
  224. }
  225. ,done: function(res,index){
  226. layer.closeAll('loading');
  227. if(res.status=='1'){
  228. //alert("上传成功~");
  229. if(typeof (object.inc) != "undefined" ){
  230. object.inc(res);
  231. }else{
  232. $(object.elem).parents(".layui-form-item").find(".layui-input-inline, input").val(res.path);
  233. //$(object.elem).parents(".layui-input-inline").prev(".layui-input-inline").find("img").attr('src',res.path);
  234. //$(object.elem).parents(".layui-input-inline").prev(".layui-input-inline").show();
  235. }
  236. }else{
  237. alert("上传失败,请重试!");
  238. }
  239. }
  240. ,error: function(){
  241. layer.closeAll('loading');
  242. alert("上传失败,请重试!");
  243. }
  244. ,field:object.field
  245. });
  246. },
  247. edit : function edit( obj={} ){
  248. if(typeof (obj.href) == "undefined"){
  249. obj.href =location.href;
  250. }
  251. if(typeof (obj.id) == "undefined"){
  252. obj.id ="form";
  253. }
  254. $.get(obj.href,{},function(data){
  255. if(typeof (obj.inc) != "undefined" ){
  256. obj.inc(data);
  257. }
  258. form.val(obj.id, data);
  259. },'json');
  260. },
  261. //搜索
  262. search : function(){
  263. form.on('submit(search)', function(data){
  264. var field=data.field;
  265. if($(data.elem).html()=="重置"){
  266. $("input").val("");
  267. field="";
  268. }
  269. table.reload('table', {
  270. where: field
  271. });
  272. return false;
  273. });
  274. },
  275. //时间选择
  276. laydate : function (start ="#start", end = "#end"){
  277. laydate.render({
  278. elem: start,
  279. max: 0
  280. });
  281. laydate.render({
  282. elem: end,
  283. max: 1
  284. });
  285. }
  286. };