index.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. var globalMethods = function(vm,swal){
  2. return {
  3. swal:swal,
  4. layer:layer,
  5. openImage:function(href){
  6. return layer.open({
  7. type: 1,
  8. title: false,
  9. closeBtn: 0,
  10. shadeClose: true,
  11. content: '<img src="'+href+'" style="display: block;width: 100%;" />'
  12. });
  13. },
  14. $swal:function(type,param,code){
  15. if(param === undefined) param = function(){};
  16. switch (type){
  17. case 'delete':
  18. if(typeof code != 'object') code = {};
  19. swal({
  20. title: code.title || "您确定要删除这条信息吗",
  21. text: code.text || "删除后将无法恢复,请谨慎操作!",
  22. type: code.type || "warning",
  23. showCancelButton: true,
  24. confirmButtonColor: "#DD6B55",
  25. confirmButtonText: code.confirm || "是的,我要删除!",
  26. cancelButtonText: code.cancel || "让我再考虑一下…",
  27. closeOnConfirm: false,
  28. closeOnCancel: false
  29. }).then(param).catch(console.log);
  30. break;
  31. case 'error':
  32. swal("错误",param,"error");
  33. break;
  34. case 'success':
  35. swal("成功",param,"success");
  36. break;
  37. case 'status':
  38. code == 200 ? this.$swal('success',param) : this.$swal('error',param);
  39. break;
  40. case 'message':
  41. swal(param);
  42. break;
  43. }
  44. },
  45. $alert:function(type,params,succFn){
  46. switch (type){
  47. case 'textarea':
  48. swal({
  49. title: params.title != undefined ? params.title.toString() : "请输入内容",
  50. input: 'textarea',
  51. inputValue: params.value || '',
  52. confirmButtonText:"提交",
  53. cancelButtonText: "取消",
  54. showCancelButton: true
  55. }).then(succFn).catch(console.log);
  56. break;
  57. }
  58. },
  59. message:function(type,config){
  60. /*content 提示内容 String -
  61. render 自定义描述内容,使用 Vue 的 Render 函数 Function -
  62. duration 自动关闭的延时,单位秒,不关闭可以写 0 Number 1.5
  63. onClose 关闭时的回调 Function -
  64. closable 是否显示关闭按钮*/
  65. vm.$Message.config({
  66. top: 1,
  67. duration:5
  68. });
  69. switch (type) {
  70. case 'success':
  71. return vm.$Message.success(config);
  72. break;
  73. case 'warning':
  74. return vm.$Message.warning(config);
  75. break;
  76. case 'error':
  77. return vm.$Message.error(config);
  78. break;
  79. case 'loading':
  80. return vm.$Message.loading(config);
  81. break;
  82. default :
  83. return vm.$Message.info(config || type);
  84. break;
  85. }
  86. },
  87. notice:function(type,config){
  88. switch (type) {
  89. case 'info':
  90. return vm.$Notice.info(config);
  91. break;
  92. case 'success':
  93. return vm.$Notice.success(config);
  94. break;
  95. case 'warning':
  96. return vm.$Notice.warning(config);
  97. break;
  98. case 'error':
  99. return vm.$Notice.error(config);
  100. break;
  101. default :
  102. return vm.$Notice.open(config || type);
  103. break;
  104. }
  105. },
  106. noticeClose:function(name){
  107. return vm.$Notice.close(name);
  108. },
  109. noticeDestroy:function(){
  110. return vm.$Notice.destroy();
  111. },
  112. modal:function(type,config){
  113. switch (type) {
  114. case 'confirm':
  115. return vm.$Modal.confirm(config);
  116. break;
  117. case 'success':
  118. return vm.$Modal.success(config);
  119. break;
  120. case 'warning':
  121. return vm.$Modal.warning(config);
  122. break;
  123. case 'error':
  124. return vm.$Modal.error(config);
  125. break;
  126. default :
  127. return vm.$Modal.info(config || type);
  128. break;
  129. }
  130. },
  131. modalRemove:function(){
  132. return vm.$modal.remove();
  133. },
  134. loading:function(type,percent){
  135. switch (type){
  136. case 'start':
  137. return vm.$Loading.start();
  138. break;
  139. case 'finish':
  140. return vm.$Loading.finish();
  141. break;
  142. case 'error':
  143. return vm.$Loading.error();
  144. break;
  145. case 'update':
  146. return vm.$Loading.update(percent);
  147. break;
  148. }
  149. }
  150. }
  151. };
  152. setTimeout(function(){
  153. mpFrame.start(function(Vue){
  154. requirejs(['sweetalert','axios'],function(swal,axios){
  155. axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
  156. axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
  157. new Vue({
  158. el:'#vm',
  159. data:{},
  160. methods:{
  161. globalApi:function(){
  162. var api = globalMethods(this,swal);
  163. api.closeModalFrame = function(name){
  164. layer.close(layer.getFrameIndex(name) || name);
  165. //关闭页面刷新
  166. // window.frames[$(".page-tabs-content .active").index()].location.reload();
  167. };
  168. api.h = this.$createElement;
  169. api.axios = axios;
  170. api.createModalFrame = this.createModalFrame;
  171. api.mpFrame = mpFrame;
  172. api.layer = layer;
  173. return api;
  174. },
  175. createModalFrame:function(title,src,opt){
  176. opt === undefined && (opt = {});
  177. var h = 0;
  178. if(window.innerHeight < 800 && window.innerHeight >= 700){
  179. h=window.innerHeight-50;
  180. }else if(window.innerHeight < 900 && window.innerHeight >= 800){
  181. h=window.innerHeight-100;
  182. }else if(window.innerHeight < 1000 && window.innerHeight >= 900){
  183. h=window.innerHeight-150;
  184. }else if(window.innerHeight >= 1000){
  185. h=window.innerHeight-200;
  186. }else{
  187. h=window.innerHeight;
  188. }
  189. var area=[(opt.w || window.innerWidth/2.4)+'px', (opt.h || h)+'px'];
  190. return layer.open({
  191. type: 2,
  192. title:title,
  193. area: area,
  194. fixed: false, //不固定
  195. maxmin: true,
  196. moveOut:false,//true 可以拖出窗外 false 只能在窗内拖
  197. anim:5,//出场动画 isOutAnim bool 关闭动画
  198. offset:'auto',//['100px','100px'],//'auto',//初始位置 ['100px','100px'] t[ 上 左]
  199. shade:0.2,//遮罩
  200. resize:true,//是否允许拉伸
  201. content: src,//内容
  202. move:'.layui-layer-title',// 默认".layui-layer-title",// 触发拖动的元素
  203. moveEnd:function(){//拖动之后回调
  204. // console.log(this);
  205. }
  206. });
  207. }
  208. },
  209. mounted:function(){
  210. window._mpApi = this.globalApi();
  211. $('.admin_close').on('click',function (e) {
  212. $('.admin_open').removeClass('open');
  213. })
  214. }
  215. })
  216. })
  217. });
  218. },0);