123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- <template>
- <div class="H5Mall">
- <div class="mainBody">
- <div
- class="item"
- @click="() => toH5Editor(item)"
- v-for="(item, index) in list"
- :key="index"
- >
- <component :is="components[item.type]" :item="item"></component>
- <div class="main_item" v-text="item.title"></div>
- </div>
- </div>
- <el-button @click="showData" class="createPageList"> 已创建页面 </el-button>
- <el-dialog v-model="show" title="已创建页面">
- <el-table :data="localList.list">
- <el-table-column property="title" label="页面名称" />
- <el-table-column label="封面图" header-align="center" width="100px">
- <template #default="scope">
- <el-image style="width: 76px; height: 100px" :src="scope.row.cover" fit="contain" />
- </template>
- </el-table-column>
- <el-table-column label="状态" width="100px">
- <template #default="scope">
- {{ h5Status[scope.row.h5Status] }}
- </template>
- </el-table-column>
- <el-table-column property="url" label="操作">
- <template #default="scope">
- <el-button
- v-if="showCopy(scope.row.url)"
- type="primary"
- link
- @click="() => copyurl(scope.row.url)"
- >
- 复制链接
- </el-button>
- <el-button
- v-if="scope.row.url"
- type="primary"
- link
- @click="() => openurl(scope.row.url)"
- >
- 打开
- </el-button>
- <el-button link type="primary" @click="() => editBL(scope)">
- 修改
- </el-button>
- <el-popconfirm
- title="是否确认删除?"
- @confirm="() => deleteBL(scope)"
- >
- <template #reference>
- <el-button link type="danger"> 删除 </el-button>
- </template>
- </el-popconfirm>
- </template>
- </el-table-column>
- </el-table>
- <template #footer>
- <el-pagination
- @current-change="currentChange"
- background
- layout="prev, pager, next"
- :total="localList.total"
- />
- </template>
- </el-dialog>
- </div>
- </template>
- <script setup>
- import { ref } from 'vue';
- import { ElMessage } from 'element-plus';
- import { useRouter } from 'vue-router';
- import H5 from './components/H5.vue';
- import LONGPAGE from './components/LONGPAGE.vue';
- import POSTER from './components/POSTER.vue';
- import {
- getTemplateList,
- getPersonalList,
- deletePersonalList,
- } from '../../api/index.js';
- const components = {
- H5,
- LONGPAGE,
- POSTER,
- };
- const router = useRouter();
- // const route = useRoute();
- const show = ref(false);
- const localList = ref({
- list: [],
- size: 20,
- page: 1,
- });
- const list = ref([]);
- const h5Status = ['生成中', '已生成'];
- getTemplateList({}).then(r => {
- list.value = r || [];
- });
- const toH5Editor = item => {
- router.push({
- path: '/h5editor',
- query: {
- item: JSON.stringify(item),
- },
- });
- };
- const showData = () => {
- localList.value.page = 1;
- show.value = true;
- personalListFunc();
- };
- const currentChange = page => {
- localList.value.page = page;
- personalListFunc();
- };
- const personalListFunc = () => {
- getPersonalList({
- data: {
- page: localList.value.page,
- size: localList.value.size,
- },
- }).then(r => {
- localList.value.list = r.records || [];
- localList.value.total = r.total || 0;
- localList.value.page += 1;
- });
- };
- const editBL = item => {
- router.push({
- path: '/h5editor',
- query: {
- item: JSON.stringify(item.row),
- },
- });
- };
- const deleteBL = item => {
- deletePersonalList({
- data: {
- operateId: item.row.operateId,
- },
- }).then(() => {
- localList.value.list.splice(item.index, 1);
- });
- };
- const openurl = url => window.open(url);
- const showCopy = url => ('clipboard' in navigator) && url
- const copyurl = url => {
- console.log(navigator)
- if (!('clipboard' in navigator)) return;
- auth().then(res => {
- if (!res) {
- // 未授权
- ElMessage({
- type: 'error',
- message: '授权未通过',
- });
- return;
- }
- navigator.clipboard.writeText(url).then(
- () => {
- ElMessage({
- type: 'success',
- message: '地址复制成功',
- });
- },
- () => {
- ElMessage({
- type: 'error',
- message: '复制失败',
- });
- }
- );
- }).catch(() => {
- ElMessage({
- type: 'error',
- message: '授权未通过',
- })
- });
- };
- const auth = () => {
- return new Promise((resolve, reject) => {
- navigator.permissions.query({ name: 'clipboard-read' }).then(
- result => {
- if (result.state == 'granted' || result.state == 'prompt') {
- resolve(true);
- } else {
- resolve(false);
- }
- },
- error => {
- reject(error);
- }
- );
- });
- };
- </script>
- <style scoped>
- .H5Mall {
- padding: 1em;
- height: 100%;
- }
- .mainBody {
- font-weight: 500;
- padding: 2em 0 1em 1em;
- }
- .mainBody .item {
- display: inline-block;
- width: 184px;
- height: 333px;
- transition: all 0.3s;
- vertical-align: middle;
- margin-right: 1em;
- border-radius: 5px;
- overflow: hidden;
- cursor: pointer;
- box-shadow: var(--el-box-shadow-lighter);
- }
- .el-image {
- height: 280px;
- }
- .main_item {
- color: #666;
- padding: 0 5px;
- margin: 5px 0;
- font-size: 14px;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- .mainBody .item:hover {
- box-shadow: var(--el-box-shadow);
- margin-top: -15px;
- }
- .mainBody img {
- vertical-align: middle;
- }
- .createPageList {
- position: absolute;
- top: 1em;
- right: 1em;
- }
- </style>
|