future il y a 1 an
Parent
commit
44c1e9ef6e
2 fichiers modifiés avec 77 ajouts et 2 suppressions
  1. 41 0
      xs-app/framework/util.ts
  2. 36 2
      xs-app/pages/bookstore/bookstore.vue

+ 41 - 0
xs-app/framework/util.ts

@@ -59,6 +59,7 @@ export class util {
 		}
 	}
 	
+	// Loadding
 	public static showLoading(title='加载中...',mask:boolean=false) {
 		uni.showLoading({
 			title:title,
@@ -70,6 +71,7 @@ export class util {
 		uni.hideLoading()
 	}
 	
+	// Toast
 	public static showInfoToast(title:string,duration=1500,mask=false) {
 		uni.showToast({
 			title:title,
@@ -97,5 +99,44 @@ export class util {
 		})
 	}
 	
+	// Modal
+	public static showModal(title:string, content:string, confirm_cb:Function=null, cancel_cb:Function=null, confirmText:string='确定', showCancel:boolean=true, cancelText:string='取消') {
+		uni.showModal({
+			title: title,
+			content: content,
+			confirmText: confirmText,
+			showCancel: showCancel,
+			cancelText: cancelText,
+			success: function (res) {
+				if (res.confirm) {
+					// console.log('用户点击确定')
+					confirm_cb && confirm_cb()
+				} else if (res.cancel) {
+					// console.log('用户点击取消')
+					cancel_cb && cancel_cb()
+				}
+			}
+		})
+	}
+	
+	public static showModalNoCancel(title:string, content:string, confirm_cb:Function=null, cancel_cb:Function=null, confirmText:string='确定'){
+		this.showModal(title,content,confirm_cb,cancel_cb,confirmText,false)
+	}
+	
+	// ActionSheet
+	public static showActionSheet(alertText:string, itemList:string[], confirm_cb:Function, cancel_cb:Function=null) {
+		uni.showActionSheet({
+			alertText:alertText,
+			itemList: itemList,
+			success: function (res) {
+				// console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
+				confirm_cb && confirm_cb(res.tapIndex)
+			},
+			fail: function (err) {
+				// console.log('showActionSheet err=',err.errMsg);
+				cancel_cb && cancel_cb()
+			}
+		});
+	}
 	
 }

+ 36 - 2
xs-app/pages/bookstore/bookstore.vue

@@ -1,9 +1,43 @@
 <template>
 	<view> 书城 </view>
+	<view style="display: flex; margin-top: 30px; height: 50px; font-size: 30px; background-color: red; justify-content: center; align-items: center;" 
+	@click="onClickTest"> 测试 </view>
 </template>
 
-<script>
+ <script >	 
+    import { util } from '../../framework/util';
+	export default {
+		data() {
+			return {
+			}
+		},
+		onLoad() {
+		},
+		methods: {
+			onClickTest() {
+				util.showLoading()
+				setTimeout(()=>{
+					util.hideLoading()
+				},1500)
+				
+				// util.showInfoToast('信息')
+				// util.showSuccessToast('成功')
+				// util.showErrorToast('失败')
+				
+				// util.showModal('标题',null,()=>{
+				// 	console.log('11111111')
+				// },null,'是吧')
+				
+				// util.showModalNoCancel('标题')
+				
+				// util.showActionSheet('你好', ['1','2','3'], (index)=>{
+				// 	console.log('确定index=',index)
+				// })
+			}
+		}
+	}
 </script>
 
-<style>
+<style lang="scss">
+	
 </style>