From 4423935d0249d35161efa7f2a095fbfc4b2fd017 Mon Sep 17 00:00:00 2001 From: 徐旺旺 <11530253@qq.com> Date: 星期一, 17 五月 2021 17:15:31 +0800 Subject: [PATCH] 定位、弹窗 --- src/components/layer/src/layer.js | 75 +++++++++---------------------------- 1 files changed, 18 insertions(+), 57 deletions(-) diff --git a/src/components/layer/src/layer.js b/src/components/layer/src/layer.js index b42ef27..2bf291b 100644 --- a/src/components/layer/src/layer.js +++ b/src/components/layer/src/layer.js @@ -1,27 +1,12 @@ import layerVue from './layer.vue' -const Notification = function (Vue, globalOption = { - msgtime: 1.5 // msg娑堝け鏃堕棿 -}) { - const NotificationConstructor = Vue.extend(layerVue) +const Layer = function (Vue) { + const LayerVueExtend = Vue.extend(layerVue) const self = {} const defOptions = { type: 0, // 0锛堜俊鎭锛岄粯璁わ級1锛堥〉闈㈠眰锛�2锛坕frame灞傦級3锛堝姞杞藉眰锛�4锛坱ips灞傦級,5msg,6prompt title: '淇℃伅', content: '', - area: 'auto', - offset: 'auto', - icon: -1, - btn: '纭畾', - time: 0, - maxmin: false, // 鏈�澶ф渶灏忓寲 - shade: true, - yes: '', - cancel: '', - tips: [0, {}], // 鏀寔涓婂彸涓嬪乏鍥涗釜鏂瑰悜锛岄�氳繃1-4杩涜鏂瑰悜璁惧畾,鍙互璁惧畾tips: [1, '#c00'] - tipsMore: false, // 鏄惁鍏佽澶氫釜tips - shadeClose: true, - scrollbar: true, // 鏄惁鍏佽娴忚鍣ㄥ嚭鐜版粴鍔ㄦ潯:榛樿鏄厑璁� - resize: false // 鏄惁鍏佽鎷変几锛岄粯璁ゆ槸涓嶅厑璁� + btn: '纭畾' } self.instances = {} self.instancesVue = [] @@ -34,17 +19,19 @@ * @param {[type]} options [description] * @return {[type]} [description] */ - self.open = function (options) { - options = mergeJson(options, defOptions) + self.open = function (opt) { + console.log(opt) + self.closeAll() + var options = mergeJson(opt, defOptions) + console.log('11111' + options) const id = `notification_${new Date().getTime()}_${seed++}` options.id = id options.layer = self - const instance = new NotificationConstructor({ + options.content.comp = Vue.extend(options.content.comp) + console.log(options) + const instance = new LayerVueExtend({ data: options }) - if (options.type === 1) { - options.content.content = Vue.extend(options.content.content) - } instance.id = id instance.vm = instance.$mount() self.instances[id] = { @@ -52,6 +39,7 @@ type: options.type } document.body.appendChild(instance.vm.$el) + instance.init() self.instancesVue[id] = { mask: '', main: instance.vm, @@ -59,28 +47,14 @@ } return id } - /** - * [description] - * @param {[type]} options [description] - * @return {[type]} [description] - */ - self.iframe = function (opt) { - let option = { - type: 1, - content: opt.content, - area: opt.area - } - option = mergeJson(option, opt) - console.log(option) - return self.open(option) - } + /** * 鍏抽棴涓�涓脊绐� * @param {[type]} id [description] * @return {[type]} [description] */ self.close = function (id) { - const oElm = document.getElementById(id) + const oElm = document.getElementById(id).parentElement if (oElm) { document.body.removeChild(oElm) delete self.instances[id] @@ -135,22 +109,9 @@ * @param {[type]} id [description] * @return {[type]} [description] */ - self.closeAll = function (type = -1) { - const types = { - page: 0, - iframe: 1 - } - if (type === -1) { - for (const k in self.instances) { - self.close(k) - } - } else { - const targetType = types[type] - for (const k in self.instances) { - if (self.instances[k].type === targetType) { - self.close(k) - } - } + self.closeAll = function () { + for (const k in self.instances) { + self.close(k) } } /** @@ -192,4 +153,4 @@ } // module.exports = Notification; -export default Notification +export default Layer -- Gitblit v1.8.0