最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

uniapp定義new plus.nativeObj.View實(shí)現(xiàn)APP端全局彈窗功能

 更新時(shí)間:2024年11月28日 10:54:58   作者:new出一個(gè)對(duì)象  
文章介紹了在UniApp中使用`newplus.nativeObj.View`實(shí)現(xiàn)彈窗的原因和方法,它定義了一個(gè)`AppPopupView`彈窗函數(shù),并在`main.js`中掛載到全局頁(yè)面,以便在任何地方調(diào)用,感興趣的朋友跟隨小編一起看看吧

為什么要用new plus.nativeObj.View在APP端實(shí)現(xiàn)彈窗?因?yàn)閡ni.showModal在APP端太難看了。

AppPopupView彈窗函數(shù)參數(shù)定義

參數(shù)一:彈窗信息(所有屬性可不填,會(huì)有默認(rèn)值)

1.title:"", //標(biāo)題

2.content:"", //內(nèi)容

3.confirmBoxColor:"", //確認(rèn)按鈕背景色

4.cancelText:"", //取消按鈕文字

5.confirmText:" //確認(rèn)按鈕文字"

6.showCancel: false, // 是否顯示取消按鈕 是:true(默認(rèn)) 否:false

7.maskClick: true // 是否允許點(diǎn)擊遮罩層關(guān)閉彈窗 是:true 否:false(默認(rèn))

參數(shù)二(cd1):點(diǎn)擊確認(rèn)按鈕執(zhí)行邏輯,

參數(shù)三(cd2):點(diǎn)擊取消按鈕執(zhí)行邏輯。

/utils/AppPopupView.js 定義彈窗文件

export default AppPopupView
function AppPopupView({
	title = '提示',
	content = '',
	confirmBoxColor = '#41a863',
	cancelText = "取消",
	confirmText = "確認(rèn)",
	showCancel = true,
	maskClick = false,
} = {}, cd1, cd2) {
	let screenWidth = plus.screen.resolutionWidth
	let screenHeight = plus.screen.resolutionHeight
	const popupViewWidth = screenWidth * 0.7
	const popupViewHeight = 80 + 20 + 20 + 90 + 10
	const viewContentPadding = 20
	const viewContentWidth = parseInt(popupViewWidth - (viewContentPadding * 2))
	let maskLayer = new plus.nativeObj.View('maskLayer', {
		top: '0px',
		left: '0px',
		height: '100%',
		width: '100%',
		backgroundColor: 'rgba(0,0,0,0.2)'
	})
	let popupViewContentList = [{
		tag: 'font',
		id: 'title',
		text: title,
		textStyles: {
			size: '18px',
			color: "#333",
			weight: "bold",
			whiteSpace: "normal"
		},
		position: {
			top: '55px',
			left: viewContentPadding + "px",
			width: viewContentWidth + "px",
			height: "30px",
		}
	}]
	popupViewContentList.push({
		tag: 'font',
		id: 'content',
		text: content || '確認(rèn)要操作嗎?',
		textStyles: {
			size: '14px',
			color: "#666",
			lineSpacing: "50%",
			align: "left"
		},
		position: {
			top: "100px",
			left: viewContentPadding + "px",
			width: viewContentWidth + "px",
			height: "18px",
		}
	});
	if (showCancel === true) { // 添加取消按鈕
		popupViewContentList.push({
			tag: 'rect',
			id: 'cancelBox',
			rectStyles: {
				radius: "3px",
				borderColor: "#f1f1f1",
				borderWidth: "1px",
			},
			position: {
				bottom: viewContentPadding + 'px',
				left: viewContentPadding + "px",
				width: (viewContentWidth - viewContentPadding) / 2 + "px",
				height: "30px",
			}
		})
		popupViewContentList.push({
			tag: 'font',
			id: 'cancelText',
			text: cancelText,
			textStyles: {
				size: '14px',
				color: "#666",
				lineSpacing: "0%",
				whiteSpace: "normal"
			},
			position: {
				bottom: viewContentPadding + 'px',
				left: viewContentPadding + "px",
				width: (viewContentWidth - viewContentPadding) / 2 + "px",
				height: "30px",
			}
		})
	}
	popupViewContentList.push({
		tag: 'rect',
		id: 'confirmBox',
		rectStyles: {
			radius: "3px",
			color: confirmBoxColor,
		},
		position: {
			bottom: viewContentPadding + 'px',
			left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px",
			width: (viewContentWidth - viewContentPadding) / 2 + "px",
			height: "30px",
		}
	})
	popupViewContentList.push({
		tag: 'font',
		id: 'confirmText',
		text: confirmText || '確認(rèn)',
		textStyles: {
			size: '14px',
			color: "#FFF",
			lineSpacing: "0%",
			whiteSpace: "normal"
		},
		position: {
			bottom: viewContentPadding + 'px',
			left: ((viewContentWidth - viewContentPadding) / 2 + viewContentPadding * 2) + "px",
			width: (viewContentWidth - viewContentPadding) / 2 + "px",
			height: "30px",
		}
	})
	if (showCancel === false) { // 如果只顯示確認(rèn)按鈕需要重新設(shè)置按鈕的width和left
		for (let i = 0; i < popupViewContentList.length; i++) {
			let item = popupViewContentList[i]
			if (item.id === 'confirmBox' || item.id === 'confirmText') {
				item.position.left = viewContentPadding + "px"
				item.position.width = viewContentWidth + "px"
			}
		}
	}
	let popupView = new plus.nativeObj.View("popupView", { //創(chuàng)建底部圖標(biāo)菜單
		tag: "rect",
		top: (screenHeight - popupViewHeight) / 2 + "px",
		left: '15%',
		height: popupViewHeight + "px",
		width: "70%"
	})
	popupView.drawRect({
		color: "#FFFFFF",
		radius: "20px"
	}, {
		top: "40px",
		height: popupViewHeight - 40 + "px",
	})
	popupView.addEventListener("click", e => {
		let maxTop = popupViewHeight - viewContentPadding
		let maxLeft = popupViewWidth - viewContentPadding
		let buttonWidth = (viewContentWidth - viewContentPadding) / 2
		if (e.clientY > maxTop - 30 && e.clientY < maxTop) {
			let maxTop = popupViewHeight - viewContentPadding;
			let maxLeft = popupViewWidth - viewContentPadding;
			let buttonWidth = (viewContentWidth - viewContentPadding) / 2;
			if (showCancel) {
				if (e.clientY > maxTop - 30 && e.clientY < maxTop) {
					if (e.clientX > viewContentPadding && e.clientX < maxLeft - buttonWidth -
						viewContentPadding) {
						// console.log("取消"); 
						maskLayer.hide()
						popupView.hide()
						cd2 && cd2()
					}
					if (e.clientX > maxLeft - buttonWidth && e.clientX < maxLeft) {
						// console.log("確認(rèn)");
						maskLayer.hide()
						popupView.hide()
						cd1 && cd1()
					}
				}
			} else {
				maskLayer.hide()
				popupView.hide()
				cd1 && cd1()
			}
		}
	})
	popupView.draw(popupViewContentList)
	// 點(diǎn)擊遮罩層
	maskLayer.addEventListener("click", function() { //處理遮罩層點(diǎn)擊
		if (maskClick) {
			maskLayer.hide();
			popupView.hide();
		}
	})
	// 顯示彈窗
	maskLayer.show()
	popupView.show()
}

在main.js掛載到全局

// #ifdef APP-PLUS
import AppPopupView from '@/utils/AppPopupView.js';
Vue.prototype.AppPopupView = AppPopupView;
// #endif

頁(yè)面調(diào)用全局彈窗

<script>
	export default {
		onLoad() {
			// #ifdef APP-PLUS
			// 參數(shù)一:彈窗信息(所有屬性可不填,會(huì)有默認(rèn)值)
			let AppPopupInfo = {
				// title:"", //標(biāo)題
				// content:"", //內(nèi)容
				// confirmBoxColor:"", //確認(rèn)按鈕背景色
				// cancelText:"", //取消按鈕文字
				// confirmText:" //確認(rèn)按鈕文字",  
				// showCancel: false, // 是否顯示取消按鈕 是:true(默認(rèn)) 否:false
				// maskClick: true // 是否允許點(diǎn)擊遮罩層關(guān)閉彈窗 是:true 否:false(默認(rèn)) 
			}
			// 參數(shù)二:點(diǎn)擊確認(rèn)按鈕執(zhí)行邏輯
			const affirmBtn = () => {
				console.log("點(diǎn)擊了確認(rèn)按鈕");
			}
			// 參數(shù)三:點(diǎn)擊取消按鈕執(zhí)行邏輯
			const cancelBtn = () => {
				console.log("點(diǎn)擊了取消按鈕");
			}
			this.AppPopupView(AppPopupInfo, affirmBtn, cancelBtn)
			// #endif
		},
	}
</script>

效果圖

到此這篇關(guān)于uniapp定義new plus.nativeObj.View實(shí)現(xiàn)APP端全局彈窗的文章就介紹到這了,更多相關(guān)uniapp全局彈窗內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue2.0 自定義組件的方法(vue組件的封裝)

    vue2.0 自定義組件的方法(vue組件的封裝)

    這篇文章主要介紹了vue2.0 自定義組件的方法(vue組件的封裝),本文通過(guò)實(shí)例代碼相結(jié)合的形式給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2018-06-06
  • Vue實(shí)現(xiàn)Dialog封裝

    Vue實(shí)現(xiàn)Dialog封裝

    在寫(xiě)業(yè)務(wù)的時(shí)候很常見(jiàn)的一個(gè)場(chǎng)景就是需要在不同的頁(yè)面調(diào)用同一個(gè)表單,常用的交互就是把表單以彈窗的形式展示,本文主要介紹了Vue實(shí)現(xiàn)Dialog封裝,感興趣的可以了解一下
    2021-07-07
  • vue3.2?Composition?API項(xiàng)目依賴(lài)升級(jí)

    vue3.2?Composition?API項(xiàng)目依賴(lài)升級(jí)

    這篇文章主要為大家介紹了vue3.2?Composition?API項(xiàng)目依賴(lài)升級(jí)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • 關(guān)于Element UI table 順序拖動(dòng)方式

    關(guān)于Element UI table 順序拖動(dòng)方式

    這篇文章主要介紹了關(guān)于Element UI table 順序拖動(dòng)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue3之Vite中由element?ui更新導(dǎo)致的啟動(dòng)報(bào)錯(cuò)解決

    Vue3之Vite中由element?ui更新導(dǎo)致的啟動(dòng)報(bào)錯(cuò)解決

    這篇文章主要介紹了Vue3之Vite中由element?ui更新導(dǎo)致的啟動(dòng)報(bào)錯(cuò)解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • Element el-button 按鈕組件的使用詳解

    Element el-button 按鈕組件的使用詳解

    這篇文章主要介紹了Element el-button 按鈕組件的使用詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • vue-router的hooks用法詳解

    vue-router的hooks用法詳解

    這篇文章主要介紹了vue-router的hooks用法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-06-06
  • Vue中父子組件通訊之todolist組件功能開(kāi)發(fā)

    Vue中父子組件通訊之todolist組件功能開(kāi)發(fā)

    這篇文章主要介紹了Vue中父子組件通訊——todolist組件功能開(kāi)發(fā)的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-05-05
  • Vue中原生template標(biāo)簽失效如何解決

    Vue中原生template標(biāo)簽失效如何解決

    這篇文章主要介紹了Vue中原生template標(biāo)簽失效如何解決,找了整一天也沒(méi)找著這事件為什么觸發(fā)不了,第二天意識(shí)到原生代碼里的template可能有問(wèn)題,在原生環(huán)境中template標(biāo)簽內(nèi)部的東西是不會(huì)渲染出來(lái)的,雖然解析器在加載頁(yè)面的時(shí)候確實(shí)會(huì)處理這部分代碼片段
    2023-02-02
  • vue響應(yīng)式Object代理對(duì)象的修改和刪除屬性

    vue響應(yīng)式Object代理對(duì)象的修改和刪除屬性

    這篇文章主要為大家介紹了vue響應(yīng)式Object代理對(duì)象的修改和刪除屬性示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08

最新評(píng)論

皮山县| 扬州市| 皮山县| 石渠县| 青州市| 威远县| 武邑县| 万年县| 宁强县| 杂多县| 泸溪县| 高要市| 宝鸡市| 乌兰县| 富源县| 大足县| 嘉禾县| 商南县| 永昌县| 海南省| 绿春县| 阿克苏市| 武义县| 衡南县| 封开县| 肥西县| 理塘县| 濮阳县| 连平县| 潜江市| 昭苏县| 蒙自县| 开江县| 雷波县| 吉林省| 陈巴尔虎旗| 中江县| 镇江市| 靖远县| 江川县| 辽宁省|