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

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

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

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

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

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

1.title:"", //標題

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

3.confirmBoxColor:"", //確認按鈕背景色

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

5.confirmText:" //確認按鈕文字"

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

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

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

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

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

export default AppPopupView
function AppPopupView({
	title = '提示',
	content = '',
	confirmBoxColor = '#41a863',
	cancelText = "取消",
	confirmText = "確認",
	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 || '確認要操作嗎?',
		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 || '確認',
		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) { // 如果只顯示確認按鈕需要重新設(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)建底部圖標菜單
		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("確認");
						maskLayer.hide()
						popupView.hide()
						cd1 && cd1()
					}
				}
			} else {
				maskLayer.hide()
				popupView.hide()
				cd1 && cd1()
			}
		}
	})
	popupView.draw(popupViewContentList)
	// 點擊遮罩層
	maskLayer.addEventListener("click", function() { //處理遮罩層點擊
		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

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

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

效果圖

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

相關(guān)文章

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

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

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

    Vue實現(xiàn)Dialog封裝

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

    vue3.2?Composition?API項目依賴升級

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

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

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

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

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

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

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

    vue-router的hooks用法詳解

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

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

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

    Vue中原生template標簽失效如何解決

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

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

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

最新評論

龙江县| 台安县| 阜宁县| 金堂县| 思茅市| 益阳市| 万宁市| 札达县| 棋牌| SHOW| 灵川县| 于都县| 图木舒克市| 习水县| 固镇县| 芒康县| 颍上县| 安康市| 新昌县| 聂拉木县| 金乡县| 娱乐| 奉新县| 定边县| 阿拉善右旗| 晴隆县| 秦皇岛市| 湾仔区| 洞头县| 商城县| 乌审旗| 寻乌县| 枣阳市| 兴隆县| 嘉峪关市| 渝中区| 青河县| 广丰县| 台江县| 泸定县| 蒙山县|