提交 67df3c70 编写于 作者: W wanganxp

完善演示例细节

上级 cfe1a2d5
...@@ -3,9 +3,7 @@ ...@@ -3,9 +3,7 @@
<page-head id="page-head" title="getElementById"></page-head> <page-head id="page-head" title="getElementById"></page-head>
<view class="uni-padding-wrap" id="snapshot-content"> <view class="uni-padding-wrap" id="snapshot-content">
<text id="text">this is text</text> <text id="text">this is text</text>
<view id="view" class="uni-common-mt" style="border: 1px solid red" <view id="view" class="uni-common-mt" style="border: 1px solid red">this is view</view>
>this is view</view
>
<button class="uni-btn" @click="changeViewStyle"> <button class="uni-btn" @click="changeViewStyle">
修改 view 宽高及背景色 修改 view 宽高及背景色
</button> </button>
...@@ -14,20 +12,20 @@ ...@@ -14,20 +12,20 @@
点击截图 点击截图
</button> </button>
</view> </view>
<image style="margin-top: 20px;" :src="snapImage" mode="aspectFit"></image> <image style="margin-top: 20px;" :src="snapImage" mode="aspectFit" @longpress="saveToAlbum"></image>
</view> </view>
</template> </template>
<script lang="uts"> <script lang="uts">
export default { export default {
data() { data() {
return { return {
snapImage:"/static/uni.png" snapImage: "/static/uni.png"
} }
}, },
methods: { methods: {
changeViewStyle(){ changeViewStyle() {
const text = uni.getElementById('text')! const text = uni.getElementById('text')!
text.style.setProperty('color', 'red') text.style.setProperty('color', 'red')
...@@ -36,25 +34,56 @@ export default { ...@@ -36,25 +34,56 @@ export default {
view.style.setProperty('height', '50px') view.style.setProperty('height', '50px')
view.style.setProperty('backgroundColor', '#007AFF') view.style.setProperty('backgroundColor', '#007AFF')
}, },
takeSnapshotClick(){ takeSnapshotClick() {
const view = uni.getElementById('snapshot-content')! const view = uni.getElementById('snapshot-content')!
view.takeSnapshot({ view.takeSnapshot({
success:function(res:TakeSnapshotSuccess){ success: function (res : TakeSnapshotSuccess) {
console.log(res.tempFilePath) console.log(res.tempFilePath)
this.snapImage = res.tempFilePath this.snapImage = res.tempFilePath
uni.showToast({ uni.showToast({
title:'截图成功' title: '截图成功,路径:' + res.tempFilePath,
icon: "none"
}) })
}, },
fail:function(res:TakeSnapshotFail){ fail: function (res : TakeSnapshotFail) {
console.log(res) console.log(res)
uni.showToast({ uni.showToast({
icon:'error', icon: 'error',
title:'截图失败' title: '截图失败'
}) })
} }
} as TakeSnapshotOptions) } as TakeSnapshotOptions)
},
saveToAlbum(e : TouchEvent) {
// console.log(e.currentTarget!.getAttribute("src"));
let filePath : string = e.currentTarget!.getAttribute("src") as string
uni.showActionSheet({
itemList: ["保存"],
success: res => {
// console.log(res.tapIndex);
if (res.tapIndex == 0) {
uni.saveImageToPhotosAlbum({
filePath: filePath,
success() {
uni.showToast({
position: "center",
icon: "none",
title: "图片保存成功,请到手机相册查看"
})
},
fail(e) {
uni.showModal({
content: "保存相册失败,errCode:" + e.errCode + ",errMsg:" + e.errMsg + ",errSubject:" + e.errSubject,
showCancel: false
});
}
})
}
},
fail: () => { },
complete: () => { }
});
}
} }
} }
}
</script> </script>
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<scroll-view style="background-color: #f5f5f5; flex-direction: row;" :scroll-x="true" :scroll-y="false" :show-scrollbar="false"> <scroll-view style="background-color: #f5f5f5; flex-direction: row;" :scroll-x="true" :scroll-y="false" :show-scrollbar="false">
<view class="flex-row" style="align-self: flex-start; flex-direction: row;"> <view class="flex-row" style="align-self: flex-start; flex-direction: row;">
<text ref="swipertab" class="sift-item" <text ref="swipertab" class="sift-item"
v-for="name in sift_item" @click=""> v-for="(name,index) in sift_item" @click="clickTH(index)">
{{name}} {{name}}
</text> </text>
</view> </view>
...@@ -57,6 +57,9 @@ ...@@ -57,6 +57,9 @@
}, },
confirm_scroll_top_input(value : number) { confirm_scroll_top_input(value : number) {
this.scroll_top_input = value this.scroll_top_input = value
},
clickTH(index:number){
console.log("点击表头:" + index);
} }
} }
} }
......
<template> <template>
<view style="width: 100%;height: 100%;"> <list-view style="flex: 1;" refresher-enabled=true @refresherrefresh="onRefresherrefresh"
<view class="banner" @click="bannerClick(banner)"> :refresher-triggered="refresherTriggered">
<list-item class="banner" @click="bannerClick(banner)">
<image class="banner-img" :src="banner.cover"></image> <image class="banner-img" :src="banner.cover"></image>
<text class="banner-title">{{ banner.title }}</text> <text class="banner-title">{{ banner.title }}</text>
</list-item>
<sticky-header>
<view style="width: 100%;height:44px;background-color: #f5f5f5;flex-direction: row;justify-content:center;align-items:center;">
<button style="height: 40px;font-size: 13px;" v-for="(name,index) in th_item" @click="clickTH(index)">
{{name}}
</button>
</view> </view>
<list-view class="uni-list-content" refresher-enabled=true @refresherrefresh="onRefresherrefresh" </sticky-header>
:refresher-triggered="refresherTriggered" scroll-y = true>
<list-item v-for="(value, index) in listData" :key="index"> <list-item v-for="(value, index) in listData" :key="index">
<view class="uni-list-cell" hover-class="uni-list-cell-hover" @click="goDetail(value)"> <view class="uni-list-cell" hover-class="uni-list-cell-hover" @click="goDetail(value)">
<view class="uni-media-list"> <view class="uni-media-list">
...@@ -21,27 +27,27 @@ ...@@ -21,27 +27,27 @@
</view> </view>
</list-item> </list-item>
</list-view> </list-view>
</view>
</template> </template>
<script> <script>
type Banner = { type Banner = {
cover: string | null, cover : string | null,
title: string | null, title : string | null,
post_id: string | null post_id : string | null
} }
type Item = { type Item = {
author_name: string, author_name : string,
cover: string, cover : string,
id: number, id : number,
post_id: string, post_id : string,
published_at: string, published_at : string,
title: string title : string
} }
export default { export default {
data() { data() {
return { return {
th_item: ["排序", "筛选"],
refresherTriggered: false, refresherTriggered: false,
banner: {} as Banner, banner: {} as Banner,
listData: [] as Item[], listData: [] as Item[],
...@@ -66,11 +72,11 @@ ...@@ -66,11 +72,11 @@
url: 'https://unidemo.dcloud.net.cn/api/banner/36kr', url: 'https://unidemo.dcloud.net.cn/api/banner/36kr',
data: data, data: data,
success: data => { success: data => {
if(this.pageVisible){ if (this.pageVisible) {
this.refresherTriggered = false this.refresherTriggered = false
if (data.statusCode == 200) { if (data.statusCode == 200) {
const result = data.data const result = data.data
if(result != null){ if (result != null) {
this.banner = result; this.banner = result;
} }
} }
...@@ -92,13 +98,13 @@ ...@@ -92,13 +98,13 @@
uni.request<Item[]>({ uni.request<Item[]>({
url: url, url: url,
method:"GET", method: "GET",
success: (res) => { success: (res) => {
if(this.pageVisible){ if (this.pageVisible) {
if (res.statusCode == 200) { if (res.statusCode == 200) {
console.log(res); console.log(res);
const result = res.data const result = res.data
if(result != null){ if (result != null) {
this.listData = result //因本接口没有更多分页数据,所以重新赋值。正常有分页的列表应该如下面push方式增加数组项 this.listData = result //因本接口没有更多分页数据,所以重新赋值。正常有分页的列表应该如下面push方式增加数组项
// this.listData.push(...result) // this.listData.push(...result)
// this.last_id = this.listData[0].id + ""; // this.last_id = this.listData[0].id + "";
...@@ -108,14 +114,14 @@ ...@@ -108,14 +114,14 @@
} }
}, },
fail: (res) => { fail: (res) => {
if(this.pageVisible){ if (this.pageVisible) {
console.log('fail', res); console.log('fail', res);
this.refresherTriggered = false this.refresherTriggered = false
} }
} }
}); });
}, },
goDetail(e: Item) { goDetail(e : Item) {
const detail = e; const detail = e;
const post_id = detail.post_id; const post_id = detail.post_id;
const cover = detail.cover; const cover = detail.cover;
...@@ -124,7 +130,7 @@ ...@@ -124,7 +130,7 @@
url: '/pages/template/list-news/detail/detail?post_id=' + post_id + "&cover=" + cover + "&title=" + title url: '/pages/template/list-news/detail/detail?post_id=' + post_id + "&cover=" + cover + "&title=" + title
}); });
}, },
bannerClick(e:Banner){ bannerClick(e : Banner) {
const detail = e; const detail = e;
const post_id = detail.post_id; const post_id = detail.post_id;
const cover = detail.cover; const cover = detail.cover;
...@@ -133,8 +139,14 @@ ...@@ -133,8 +139,14 @@
url: '/pages/template/list-news/detail/detail?post_id=' + post_id + "&cover=" + cover + "&title=" + title url: '/pages/template/list-news/detail/detail?post_id=' + post_id + "&cover=" + cover + "&title=" + title
}); });
}, },
clickTH(index:number){
uni.showModal({
content: "点击表头项:" + index,
showCancel: false
});
},
onRefresherrefresh() { onRefresherrefresh() {
if(this.pageVisible){ if (this.pageVisible) {
this.refresherTriggered = true this.refresherTriggered = true
this.getBanner(); this.getBanner();
this.getList(); this.getList();
...@@ -188,7 +200,7 @@ ...@@ -188,7 +200,7 @@
justify-content: space-around; justify-content: space-around;
} }
.uni-list-content{ .uni-list-content {
background-color: #FFFFFF; background-color: #FFFFFF;
position: relative; position: relative;
display: flex; display: flex;
...@@ -200,7 +212,7 @@ ...@@ -200,7 +212,7 @@
.uni-media-list-text-top { .uni-media-list-text-top {
/* height: 74rpx; */ /* height: 74rpx; */
font-size: 28rpx; font-size: 28rpx;
lines:2; lines: 2;
overflow: hidden; overflow: hidden;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册