easybill-ui 0.1.17 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,7 @@
24
24
  </template>
25
25
 
26
26
  <script lang="ts">
27
- import { defineComponent, reactive, provide, ref, Ref, computed, watch, PropType } from "vue"
27
+ import { defineComponent, reactive, provide, ref, Ref, computed, watch, PropType, getCurrentInstance } from "vue"
28
28
  import { isFunction, isAsyncFunction } from "./utils/is"
29
29
  import { deepClone } from "./utils/common"
30
30
  import components from "./components"
@@ -65,6 +65,7 @@ export default defineComponent({
65
65
  const sFormSchema: Ref<FormSchema> = ref(props.formSchema)
66
66
  let formModel = reactive<Fields>(props.modelValue || {})
67
67
  const curdFormContext = reactive<FormContext>({} as FormContext)
68
+ const instance = getCurrentInstance()
68
69
  watch(
69
70
  () => props.modelValue,
70
71
  (val) => {
@@ -100,7 +101,7 @@ export default defineComponent({
100
101
  if (item.asyncOptions && (item.autoload || typeof item.autoload == "undefined") && (isFunction(item.asyncOptions) || isAsyncFunction(item.asyncOptions))) {
101
102
  item.loading = true
102
103
  item.options = await item.asyncOptions(formModel, item, curdFormContext).finally(() => (item.loading = false))
103
- item.eventObject?.optionLoaded && item.eventObject?.optionLoaded(formModel, item, curdFormContext)
104
+ !instance?.isUnmounted && item.eventObject?.optionLoaded && item.eventObject?.optionLoaded(formModel, item, curdFormContext)
104
105
  } else if (item.prop && item.asyncValue && (isFunction(item.asyncValue) || isAsyncFunction(item.asyncValue))) {
105
106
  // 异步默认值
106
107
  item.loading = true
@@ -134,23 +135,23 @@ export default defineComponent({
134
135
  // 调用某个表单项的异步数据接口
135
136
  const loadOptions = async (prop: string, option?: any) => {
136
137
  const cur = sFormSchema.value.formItem.find((a) => a.prop == prop)
137
- if (cur && cur.asyncOptions) {
138
+ if (cur && cur.asyncOptions && !instance?.isUnmounted) {
138
139
  cur.loading = true
139
140
  cur.options =
140
141
  (await cur
141
142
  .asyncOptions(formModel, cur, curdFormContext, option)
142
143
  .catch((err) => console.error("loadOptionError", err))
143
144
  .finally(() => (cur.loading = false))) || []
144
- cur.eventObject?.optionLoaded && cur.eventObject?.optionLoaded(formModel, cur, curdFormContext, option)
145
+ !instance?.isUnmounted && cur.eventObject?.optionLoaded && cur.eventObject?.optionLoaded(formModel, cur, curdFormContext, option)
145
146
  }
146
147
  return cur
147
148
  }
148
149
  // 给某个item赋值options
149
- const setOptions = async (prop: string, options: CurdFormOptionItem[]) => {
150
+ const setOptions = async (prop: string, options: CurdFormOptionItem[], option?: any) => {
150
151
  const cur = sFormSchema.value.formItem.find((a) => a.prop == prop)
151
152
  if (cur) {
152
153
  cur.options = options
153
- cur.eventObject?.optionLoaded && cur.eventObject?.optionLoaded(formModel, cur, curdFormContext)
154
+ !instance?.isUnmounted && cur.eventObject?.optionLoaded && cur.eventObject?.optionLoaded(formModel, cur, curdFormContext, option)
154
155
  }
155
156
  // return cur
156
157
  }
@@ -462,6 +462,9 @@ defineExpose({
462
462
  setTotal,
463
463
  search,
464
464
  listQuery,
465
+ fetchCreate: create,
466
+ fetchEdit: create,
467
+ fetchRemove: startremove,
465
468
  getEl() {
466
469
  return instance?.proxy?.$el
467
470
  },
@@ -17,7 +17,7 @@
17
17
  <div v-if="!$slots.default" class="detail-info-body" :class="[props.showType]">
18
18
  <div class="table-detail-col" v-for="(item, i) in list" :key="i" :span="item.span" :style="getItemStyle(item)">
19
19
  <div class="item-col">
20
- <div v-if="item.label" class="label" :style="{ width: getLabelWidth(item), justifyContent: props.labelPosition || item.labelPosition }">
20
+ <div v-if="item.label" class="label" :style="getLabelStyle(item)">
21
21
  <span>{{ item.label }}</span>
22
22
  <DetailInfoTooltip :tooltip="item.tooltip" />{{ props.showType == "table" ? "" : ":" }}
23
23
  </div>
@@ -30,6 +30,7 @@
30
30
  <template v-else-if="item.type == 'image'">
31
31
  <el-image :src="item.value" :preview-src-list="[item.value]" style="width: 40px; height: 40px; vertical-align: top" :fit="'cover'" v-bind="item.props"></el-image>
32
32
  </template>
33
+ <component v-else-if="item.type" :is="item.type" v-model="item.value" v-bind="item.props"></component>
33
34
  <template v-else><DetailInfoContent :data="item" /></template>
34
35
  </template>
35
36
  </div>
@@ -52,8 +53,8 @@ import DetailInfoContent from "./DetailInfoContent.vue"
52
53
 
53
54
  const props = defineProps({
54
55
  data: {
55
- type: Object as PropType<Array<DetailDataItem>>,
56
- default: () => ({}),
56
+ type: Array as PropType<Array<DetailDataItem>>,
57
+ default: () => [],
57
58
  },
58
59
  title: {
59
60
  type: String,
@@ -74,7 +75,8 @@ const props = defineProps({
74
75
  },
75
76
  })
76
77
  const list = computed(() => {
77
- return props.data.filter((item) => {
78
+ const d = props.data || []
79
+ return d.filter((item) => {
78
80
  if (typeof item.hidden == "function") return !item.hidden(props.data)
79
81
  if (typeof item.hidden != "undefined") return !item.hidden
80
82
  return true
@@ -85,6 +87,15 @@ const getLabelWidth = (dataItem: DetailDataItem): string => {
85
87
  const isNum = typeof labelWidth == "number" || (typeof labelWidth == "string" && /^\d+$/.test(labelWidth))
86
88
  return !isNum ? labelWidth + "" : labelWidth + "px"
87
89
  }
90
+ const getLabelStyle = (item: DetailDataItem) => {
91
+ let s = item.labelStyle
92
+ if (typeof s == "object") {
93
+ s = Object.keys(item.labelStyle)
94
+ .map((a) => a + ":" + item.labelStyle[a])
95
+ .join(";")
96
+ }
97
+ return `width: ${getLabelWidth(item)}; justifyContent: ${item.labelPosition || props.labelPosition};` + s
98
+ }
88
99
  const getItemStyle = (dataItem: DetailDataItem) => {
89
100
  const width = (100 * (dataItem.span || 24)) / 24 + "%"
90
101
  return { width: width, flex: "0 0 " + width }
@@ -2,9 +2,6 @@
2
2
  <el-tooltip v-if="props.data.showOverflowTooltip" v-bind="getTooltipProps">
3
3
  <div v-if="props.data.rawContent" style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden" v-html="props.data.value"></div>
4
4
  <div v-else style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden">{{ props.data.value }}</div>
5
- <!-- <template #content>
6
- <div v-html="props.data.value"></div>
7
- </template> -->
8
5
  </el-tooltip>
9
6
  <template v-else>
10
7
  <div v-if="props.data.rawContent" v-html="props.data.value"></div>
@@ -1,5 +1,6 @@
1
1
  import { ElTooltipProps } from "element-plus"
2
2
  import { OptionItem } from "../../ConstantStatus/src/types"
3
+ import { defineComponent } from "vue"
3
4
 
4
5
  export interface DetailDataItem extends Record<string, any> {
5
6
  label?: string
@@ -9,12 +10,13 @@ export interface DetailDataItem extends Record<string, any> {
9
10
  /** 当前数据的选项,里面包含的图标、颜色信息会自动显示 */
10
11
  options?: Array<OptionItem>
11
12
  /** type为image时,会把value当做image的url来显示图片 */
12
- type?: string
13
+ type?: string | ReturnType<typeof defineComponent>
13
14
  labelWidth?: number
14
15
  props?: Record<string, string>
15
16
  slot?: string
16
17
  tooltip?: string | import("element-plus/es/components/tooltip").ElTooltipProps
17
18
  labelPosition?: "left" | "right" | "center"
19
+ labelStyle?: string | Record<string, any>
18
20
  showOverflowTooltip?: boolean | ElTooltipProps
19
21
  rawContent?: boolean
20
22
  hidden?: boolean | ((data: DetailDataItem[]) => boolean)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easybill-ui",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "A component library for easybill",
5
5
  "author": "tuchongyang <779311998@qq.com>",
6
6
  "private": false,
@@ -14,5 +14,5 @@
14
14
  "publishConfig": {
15
15
  "access": "public"
16
16
  },
17
- "gitHead": "d252ca9411fe5b50332c38f62cb719ea98bf2fc9"
17
+ "gitHead": "e4c25822f2d7360b65b9d5721415af2ee8e1a6a2"
18
18
  }