Showing
3 changed files
with
112 additions
and
10 deletions
src/components/ButtonField/index.vue
0 → 100644
| 1 | +<!-- | ||
| 2 | + * @Date: 2022-08-29 14:31:20 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2022-11-22 14:23:49 | ||
| 5 | + * @FilePath: /data-table/src/components/DividerField/index.vue | ||
| 6 | + * @Description: 按钮组件 | ||
| 7 | +--> | ||
| 8 | +<template> | ||
| 9 | + <div class="button-field-page"> | ||
| 10 | + <van-row justify="center" gutter="20"> | ||
| 11 | + <van-col v-for="item in props.item.component_props.config" key="index"> | ||
| 12 | + <van-button | ||
| 13 | + @click="handleButton(item)" | ||
| 14 | + :icon="iconType(item)" | ||
| 15 | + :color="item.background ? item.background : backgroundColor" | ||
| 16 | + >{{ item.text }} | ||
| 17 | + </van-button> | ||
| 18 | + </van-col> | ||
| 19 | + </van-row> | ||
| 20 | + </div> | ||
| 21 | + <van-overlay :show="show" @click="onClose"> | ||
| 22 | + <div class="wrapper"> | ||
| 23 | + <div class="block"> | ||
| 24 | + <van-image width="100%" fit="cover" :src="qr_url" /> | ||
| 25 | + </div> | ||
| 26 | + </div> | ||
| 27 | + </van-overlay> | ||
| 28 | +</template> | ||
| 29 | + | ||
| 30 | +<script setup> | ||
| 31 | +import { styleColor } from "@/constant.js"; | ||
| 32 | + | ||
| 33 | +const props = defineProps({ | ||
| 34 | + item: Object, | ||
| 35 | +}); | ||
| 36 | + | ||
| 37 | +const show = ref(false); | ||
| 38 | +const backgroundColor = styleColor.baseColor; | ||
| 39 | + | ||
| 40 | +const iconType = (item) => { | ||
| 41 | + if (item.type === "tel") return "phone-o"; | ||
| 42 | + if (item.type === "link") return "link-o"; | ||
| 43 | + if (item.type === "qr") return "qr"; | ||
| 44 | +}; | ||
| 45 | + | ||
| 46 | +const qr_url = ref(""); | ||
| 47 | +const handleButton = ({ type, content }) => { | ||
| 48 | + if (type === "tel") { | ||
| 49 | + location.href = "tel://" + content; | ||
| 50 | + } | ||
| 51 | + if (type === "link") { | ||
| 52 | + location.href = content; | ||
| 53 | + } | ||
| 54 | + if (type === "qr") { | ||
| 55 | + show.value = true; | ||
| 56 | + qr_url.value = content; | ||
| 57 | + } | ||
| 58 | +}; | ||
| 59 | + | ||
| 60 | +const onClose = () => { | ||
| 61 | + show.value = false; | ||
| 62 | +}; | ||
| 63 | + | ||
| 64 | +onMounted(() => { | ||
| 65 | + console.warn(props.item.component_props.config); | ||
| 66 | +}); | ||
| 67 | +</script> | ||
| 68 | + | ||
| 69 | +<style lang="less" scoped> | ||
| 70 | +.button-field-page { | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +.wrapper { | ||
| 74 | + display: flex; | ||
| 75 | + align-items: center; | ||
| 76 | + justify-content: center; | ||
| 77 | + height: 100%; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +.block { | ||
| 81 | + width: 10rem; | ||
| 82 | + height: 10rem; | ||
| 83 | + background-color: #fff; | ||
| 84 | +} | ||
| 85 | +</style> |
| ... | @@ -25,6 +25,7 @@ import MarqueeField from '@/components/MarqueeField/index.vue' | ... | @@ -25,6 +25,7 @@ import MarqueeField from '@/components/MarqueeField/index.vue' |
| 25 | import ContactField from '@/components/ContactField/index.vue' | 25 | import ContactField from '@/components/ContactField/index.vue' |
| 26 | import RuleField from '@/components/RuleField/index.vue' | 26 | import RuleField from '@/components/RuleField/index.vue' |
| 27 | import MultiRuleField from '@/components/MultiRuleField/index.vue' | 27 | import MultiRuleField from '@/components/MultiRuleField/index.vue' |
| 28 | +import ButtonField from '@/components/ButtonField/index.vue' | ||
| 28 | 29 | ||
| 29 | /** | 30 | /** |
| 30 | * 生成自定义组件类型 | 31 | * 生成自定义组件类型 |
| ... | @@ -150,6 +151,10 @@ export function createComponentType(data) { | ... | @@ -150,6 +151,10 @@ export function createComponentType(data) { |
| 150 | item.name = item.key; | 151 | item.name = item.key; |
| 151 | item.component = RuleField; | 152 | item.component = RuleField; |
| 152 | } | 153 | } |
| 154 | + if (item.component_props.name === 'button') { | ||
| 155 | + item.name = item.key; | ||
| 156 | + item.component = ButtonField; | ||
| 157 | + } | ||
| 153 | if (item.component_props.name === 'multi_rule') { | 158 | if (item.component_props.name === 'multi_rule') { |
| 154 | item.name = item.key; | 159 | item.name = item.key; |
| 155 | item.value = []; | 160 | item.value = []; | ... | ... |
| ... | @@ -108,16 +108,28 @@ const formatData = (data) => { | ... | @@ -108,16 +108,28 @@ const formatData = (data) => { |
| 108 | const component_props = { | 108 | const component_props = { |
| 109 | name: field.component_code, | 109 | name: field.component_code, |
| 110 | }; | 110 | }; |
| 111 | - field.property_list.forEach((prop) => { | 111 | + if (field.component_type === "h5edit") { |
| 112 | - const key = prop["property_code"]; | 112 | + // 编辑组件 |
| 113 | - const obj = { | 113 | + field.property_list.forEach((prop) => { |
| 114 | - [key]: | 114 | + const key = prop["property_code"]; |
| 115 | - prop["setting_value"].length > 1 | 115 | + const obj = { |
| 116 | - ? prop["setting_value"] | 116 | + [key]: |
| 117 | - : prop["setting_value"][0], | 117 | + prop["setting_value"].length > 1 |
| 118 | - }; | 118 | + ? prop["setting_value"] |
| 119 | - Object.assign(component_props, obj); | 119 | + : prop["setting_value"][0], |
| 120 | - }); | 120 | + }; |
| 121 | + Object.assign(component_props, obj); | ||
| 122 | + }); | ||
| 123 | + } else { | ||
| 124 | + // 展示组件 | ||
| 125 | + field.property_list.forEach((prop) => { | ||
| 126 | + const key = prop["property_code"]; | ||
| 127 | + const obj = { | ||
| 128 | + [key]: prop["setting_value"], | ||
| 129 | + }; | ||
| 130 | + Object.assign(component_props, obj); | ||
| 131 | + }); | ||
| 132 | + } | ||
| 121 | // 绑定组件名称标识 | 133 | // 绑定组件名称标识 |
| 122 | const temp = { | 134 | const temp = { |
| 123 | key: field.field_name, | 135 | key: field.field_name, | ... | ... |
-
Please register or login to post a comment