Files
t/pages2/edit_list/edit_list.vue
T

269 lines
5.8 KiB
Vue

<template>
<view class="page">
<view class="" style="padding: 10rpx;">
<u-subsection
:list="list"
font-size="20"
:current="current"
mode="subsection"
@change="sectionChange">
</u-subsection>
</view>
<u-popup :show="show" @close="close" @open="open">
<view class="popup-page">
<view class="">
<uni-list>
<uni-list-item
@click="editItem(selectIndex)"
:show-extra-icon="true"
:extra-icon="iconList.edit"
clickable="true"
title="文章编辑" />
</uni-list>
<uni-list>
<uni-list-item
@click="settingItem(selectIndex)"
:show-extra-icon="true"
:extra-icon="iconList.setting"
clickable="true"
title="文章设置" />
</uni-list>
<uni-list>
<uni-list-item
@click="deleteItem(selectIndex)"
:show-extra-icon="true"
:extra-icon="iconList.delete"
clickable="true"
title="删除" />
</uni-list>
</view>
<view class="close-button" @click="close()">
取消
</view>
</view>
</u-popup>
<view class="" v-if="current === 1">
<view class="container" style="display: flex;flex-wrap: wrap;">
<view class=""
style="box-sizing: border-box;width: 50%;border-radius: 12rpx;" v-for="(item, index) in cms_list">
<uni-card margin="5" spacing="0" @click="editItem(index)">
<cloud-image
width="100%"
height="200rpx"
mode="scaleToFill"
:src="Array.isArray(item.thumbnail) && item.thumbnail.length > 0?item.thumbnail[0]:''">
</cloud-image>
<text class="uni-body">
{{ item.title }}
</text>
<view
slot="actions"
class="card-actions">
<view
class="card-actions-item">
<text
class="card-actions-item-text">
阅读量 {{ item.view_count }}
</text>
</view>
<view
class="card-actions-item"
@click.stop="selectMore(index)">
<uni-icons type="more-filled" size="18" color="#999"></uni-icons>
</view>
</view>
</uni-card>
</view>
</view>
</view>
</view>
</template>
<script>
import { ref, computed, onMounted } from 'vue'
import cloudImage from "@/components/cloud-image.vue"
import uSubsection from "@/uni_modules/uview-ui/components/u-subsection/u-subsection.vue"
import uPopup from "@/uni_modules/uview-ui/components/u-popup/u-popup.vue"
import { store } from '@/pages3/uni_modules/uni-id-pages/common/store.js'
export default {
components: {
uSubsection,
cloudImage,
uPopup
},
setup() {
const list = ref(['动态', '作品', '相册', '收藏'])
const current = ref(1)
const show = ref(false)
const selectIndex = ref(0)
const cms_list = ref([])
const iconList = {
delete: { color: '#f55', size: '22', type: 'closeempty' },
setting: { color: '#888', size: '22', type: 'gear-filled' },
edit: { color: '#888', size: '22', type: 'compose' }
}
const userInfo = computed(() => store.userInfo)
onMounted(async () => {
if (!userInfo.value._id) {
uni.showToast({ title: '请先登录', icon: 'none' })
setTimeout(() => uni.navigateBack(), 1000)
return
}
uni.showLoading({ title: '加载中' })
try {
let res = await uniCloud.importObject("uni-cms-articles")
.get_cms_articles_for_userId({ user_id: userInfo.value._id })
cms_list.value = res.data || []
} catch (e) {
console.error(e)
uni.showToast({ title: '加载失败,请重试', icon: 'none' })
} finally {
uni.hideLoading()
}
})
function sectionChange(index) {
current.value = index
}
function selectMore(index) {
show.value = true
selectIndex.value = index
}
function close() {
show.value = false
}
function open() {
show.value = true
}
async function deleteItem(index) {
let res = await uniCloud.importObject("uni-cms-articles").del_cms_articles({ id: cms_list.value[index]._id })
if (res.code === 200) {
cms_list.value.splice(index, 1)
}
close()
}
async function editItem(index) {
let cms = cms_list.value[index]
if (!cms) return
uni.setStorageSync("cms", cms)
await toCmsEdit(cms._id)
}
async function toCmsEdit(id) {
uni.navigateTo({
url: "/pages2/editCms/editCms?id=" + id
})
}
function settingItem(index) {
let cms = cms_list.value[index]
if (!cms) return
uni.setStorageSync("cms", cms)
uni.navigateTo({ url: "/pages2/editCms/editSetting" })
}
return {
list,
current,
show,
selectIndex,
cms_list,
iconList,
userInfo,
sectionChange,
selectMore,
close,
open,
deleteItem,
editItem,
toCmsEdit,
settingItem
}
}
}
</script>
<style lang="scss">
.page {
padding: 20rpx;
}
.container {
overflow: hidden;
}
.custom-cover {
flex: 1;
flex-direction: row;
position: relative;
}
.cover-content {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 40px;
background-color: rgba($color: #000000, $alpha: 0.4);
display: flex;
flex-direction: row;
align-items: center;
padding-left: 15px;
font-size: 14px;
color: #fff;
}
.card-actions {
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
height: 45px;
border-top: 1px #eee solid;
}
.card-actions-item {
display: flex;
flex-direction: row;
align-items: center;
}
.card-actions-item-text {
font-size: 12px;
color: #666;
margin-left: 5px;
}
.cover-image {
flex: 1;
height: 150px;
}
.no-border {
border-width: 0;
}
.close-button {
background-color: #fff;
text-align: center;
border: 3rpx solid #fff;
height: 50rpx;
width: 100%;
padding: 5rpx;
margin-top: 20rpx;
margin-bottom: 10rpx;
}
.popup-page {
background-color: #eee;
}
</style>