refactor: page data local key

pull/4/head
bqy_fe 4 years ago
parent a0482d493b
commit 25b3d69041
  1. 10
      README.md
  2. 2
      preview/index.html
  3. 12
      preview/router.ts
  4. 6
      preview/views/preview.vue
  5. 14
      src/enums/index.ts
  6. 2
      src/packages/container-component/index.ts
  7. 10
      src/visual-editor/components/left-aside/components/page-tree/index.vue
  8. 5
      src/visual-editor/hooks/useVisualData.ts

@ -32,6 +32,16 @@
目前在使用表单时,需要把相关的`表单控件`放到`表单容器`内部,并且需要将`按钮`放到`表单容器`内,
然后再讲`按钮的type`设置为`表单提交按钮`这时候点击提交按钮才会自动收集表单容器内部的所有字段和值
## 浏览器支持
本地开发推荐使用`Chrome 80+` 浏览器
支持现代浏览器, 不支持 IE
| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt=" Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>IE | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt=" Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Safari |
| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| not support | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
### 提交规范
- `feat` 增加新功能

@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>第二个页面</title>
<title>效果页</title>
</head>
<body>
<div id="app"></div>

@ -1,4 +1,6 @@
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import { VisualEditorModelValue } from '@/visual-editor/visual-editor.utils'
import { CacheEnum } from '@/enums'
const routes: Array<RouteRecordRaw> = [
{
@ -12,4 +14,14 @@ const router = createRouter({
routes
})
// 获取本地缓存的页面数据
const jsonData: VisualEditorModelValue = JSON.parse(
localStorage.getItem(CacheEnum.PAGE_DATA_KEY) as string
)
router.beforeEach((to) => {
document.title = jsonData?.pages?.[to.path]?.title ?? document.title
return true
})
export default router

@ -8,6 +8,7 @@
import { defineComponent, reactive, toRefs } from 'vue'
import { Toast } from 'vant'
import { visualConfig } from '@/visual.config'
import { CacheEnum } from '@/enums'
import { VisualEditorModelValue } from '@/visual-editor/visual-editor.utils'
import SlotItem from './slot-item.vue'
import router from '../router'
@ -25,7 +26,10 @@ export default defineComponent({
SlotItem
},
setup() {
const jsonData: VisualEditorModelValue = JSON.parse(localStorage.getItem('jsonData') as string)
const jsonData: VisualEditorModelValue = JSON.parse(
localStorage.getItem(CacheEnum.PAGE_DATA_KEY) as string
)
if (!jsonData || !Object.keys(jsonData.pages)) {
Toast.fail('当前没有可以预览的页面!')
}

@ -0,0 +1,14 @@
/**
* @name: index
* @author:
* @date: 2021/5/26 22:55
* @description
* @update: 2021/5/26 22:55
*/
/**
* @description
*/
export enum CacheEnum {
PAGE_DATA_KEY = 'PAGE_DATA_KEY'
}

@ -7,5 +7,5 @@ Object.keys(modules).forEach((key: string) => {
components[name] = modules[key]?.default || modules[key]
})
console.log(components, 'base-widgets')
console.log(components, 'container-component')
export default components

@ -68,6 +68,7 @@
import { defineComponent, reactive, computed, toRefs } from 'vue'
import { useVisualData } from '@/visual-editor/hooks/useVisualData'
import { useRouter, useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
export default defineComponent({
name: 'PageTree',
@ -137,6 +138,9 @@ export default defineComponent({
//
const onSubmit = async () => {
const { title, path } = state.form
if (title.trim() == '' || path.trim() == '') {
return ElMessage.error('标题或路径不能为空!')
}
if (state.operatePageData) {
updatePage({ newPath: path, oldPath: state.operatePageData.path || path, page: { title } })
await router.replace(path)
@ -164,11 +168,11 @@ export default defineComponent({
<style lang="scss" scoped>
.custom-tree-node {
flex: 1;
display: flex;
padding-right: 8px;
font-size: 14px;
flex: 1;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
}
</style>

@ -15,9 +15,10 @@ import {
} from '@/visual-editor/visual-editor.utils'
import { visualConfig } from '@/visual.config'
import { CacheEnum } from '@/enums'
// 保存到本地JSON数据的key
export const localKey = 'jsonData'
export const localKey = CacheEnum.PAGE_DATA_KEY
// 注入jsonData的key
export const injectKey = Symbol('injectKey')
@ -41,7 +42,7 @@ export interface VisualData {
export const initVisualData = (): VisualData => {
const jsonData: VisualEditorModelValue = JSON.parse(
sessionStorage.getItem('jsonData') as string
sessionStorage.getItem(localKey) as string
) || {
container: {
width: 360,

Loading…
Cancel
Save