_dialog.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import Vue from 'vue';
  2. import settings from './dialog.vue';
  3. let DialogConstructor = Vue.extend(settings);
  4. let inst;
  5. let Dialog = function(options) {
  6. options.id = options.id || 'nut-dialog-default-id';
  7. if (options.type === 'image' && typeof options.closeBtn === 'undefined') {
  8. options.closeBtn = true;
  9. }
  10. inst = new DialogConstructor({
  11. propsData: options
  12. });
  13. inst.vm = inst.$mount();
  14. let dialogDom = document.querySelector('#' + options.id);
  15. if (options.id && dialogDom) {
  16. dialogDom.parentNode.replaceChild(inst.$el, dialogDom);
  17. } else {
  18. document.body.appendChild(inst.$el);
  19. }
  20. // setTimeout(() => {
  21. // // 设置z-index保证最新的弹窗再最上面
  22. // let dialogThis = document.querySelector('#'+options.id);
  23. // var nutDialogWrapper = document.getElementsByClassName('nut-dialog-wrapper');
  24. // var zIndexNum = 100 + (10 * (nutDialogWrapper.length));
  25. // dialogThis.style.zIndex = zIndexNum;
  26. // setTimeout(function() {
  27. // for(var i = 0;i < nutDialogWrapper.length;i++) {
  28. // nutDialogWrapper[i].style.zIndex = zIndexNum - 1 - i;
  29. // }
  30. // }, 0);
  31. // }, 10);
  32. Vue.nextTick(() => {
  33. inst.visible = true;
  34. });
  35. };
  36. Dialog.closed = function() {
  37. if (inst) {
  38. inst.close()
  39. }
  40. }
  41. export default Dialog;