WindowService.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { Notify, Uuid } from 'pc-component-v3';
  2. export default {
  3. /**
  4. * 打开一个新的窗口
  5. * @param {*} url 打开指定的页面的URL。
  6. * @param {*} name 窗口的名称
  7. */
  8. open: function (url, name, closeCallback) {
  9. if (window.dd.env.platform !== 'notInDingTalk') {
  10. // 方案一:打开模态框或侧边栏
  11. window.dd.biz.util.openModal({
  12. url: url,
  13. title: name,
  14. onSuccess: function (res) {
  15. // 调用成功时回调
  16. console.log(res);
  17. if(closeCallback != null){
  18. closeCallback();
  19. }
  20. },
  21. onFail: function (err) {
  22. // 调用失败时回调
  23. console.log(err);
  24. //Notify.error("页面打开失败", "页面(" + url + ")打开失败,失败原因:" + err, false);
  25. if(closeCallback != null){
  26. closeCallback();
  27. }
  28. },
  29. });
  30. } else {
  31. let winObj = window.open(url, '_blank');
  32. if(closeCallback != null){
  33. var loop = setInterval(function() {
  34. if(winObj.closed) {
  35. clearInterval(loop);
  36. closeCallback();
  37. }
  38. }, 1000);
  39. }
  40. }
  41. },
  42. /**
  43. * 关闭窗口
  44. */
  45. close: function () {
  46. if (window.dd.env.platform !== 'notInDingTalk') {
  47. // 方案一:关闭模态框或侧边栏
  48. // dd.biz.navigation.quit只在SlidePanel和Modal里起作用。
  49. window.dd.biz.navigation.quit({
  50. message: '',//退出信息,传递给openModal或者openSlidePanel的onSuccess函数的result参数
  51. onSuccess : function(result) {
  52. },
  53. onFail : function(err) {
  54. // 调用失败时回调
  55. console.log(err);
  56. //Notify.error("页面关闭失败", "页面关闭失败,失败原因:" + err, false);
  57. },
  58. });
  59. } else {
  60. window.close();
  61. }
  62. },
  63. };