nbwansui 1.0.2 → 1.0.3

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.
@@ -0,0 +1,9 @@
1
+ import { KEY_COMPONENT_NAME } from '/@/utils/avue/global/variable.js'
2
+ import bem from '/@/utils/avue/utils/bem.js'
3
+ export default function (sfc) {
4
+ sfc.name = KEY_COMPONENT_NAME + sfc.name
5
+ sfc.mixins = sfc.mixins || []
6
+ sfc.mixins.push(bem)
7
+
8
+ return sfc
9
+ }
@@ -0,0 +1,172 @@
1
+ import {
2
+ ARRAY_LIST,
3
+ ARRAY_VALUE_LIST,
4
+ DATE_LIST,
5
+ DIC_SPLIT,
6
+ INPUT_LIST,
7
+ KEY_COMPONENT_NAME,
8
+ MULTIPLE_LIST,
9
+ RANGE_LIST,
10
+ SELECT_LIST,
11
+ } from '/@/utils/avue/global/variable.js'
12
+ import { t } from '/@/utils/avue/locale/index.js'
13
+ import { createObj, detailDataType, findObject } from '/@/utils/avue/utils/util.js'
14
+ import { validatenull } from '/@/utils/avue/utils/validate.js'
15
+ /**
16
+ * 计算级联属性
17
+ */
18
+ export const calcCascader = (list = []) => {
19
+ list.forEach((ele) => {
20
+ const cascader = ele.cascader
21
+ if (!validatenull(cascader)) {
22
+ const parentProp = ele.prop
23
+ cascader.forEach((citem) => {
24
+ const column = findObject(list, citem)
25
+ if (column) column.parentProp = parentProp
26
+ })
27
+ }
28
+ })
29
+ return list
30
+ }
31
+ /**
32
+ * 计算空白列row
33
+ */
34
+ let count = 0
35
+ export const calcCount = (ele, spanDefault = 12, init = false) => {
36
+ if (init) count = 0
37
+ const spanAll = 24
38
+ count = count + (ele.span || spanDefault) + (ele.offset || 0)
39
+ if (count === spanAll) {
40
+ count = 0
41
+ } else if (count > spanAll) {
42
+ count = 0 + (ele.span || spanDefault) + (ele.offset || 0)
43
+ } else if (ele.row && count !== spanAll) {
44
+ ele.count = spanAll - count
45
+ count = 0
46
+ }
47
+ return ele
48
+ }
49
+
50
+ /**
51
+ * 初始化数据格式
52
+ */
53
+ export const initVal = (value, safe) => {
54
+ const { type, multiple, dataType, separator = DIC_SPLIT, alone, emitPath, range } = safe
55
+ let list = value
56
+ if (
57
+ (MULTIPLE_LIST.includes(type) && multiple == true) ||
58
+ (ARRAY_VALUE_LIST.includes(type) && emitPath !== false) ||
59
+ (RANGE_LIST.includes(type) && range == true)
60
+ ) {
61
+ if (!Array.isArray(list)) {
62
+ if (validatenull(list)) {
63
+ list = []
64
+ } else {
65
+ list = `${list}`.split(separator) || []
66
+ }
67
+ }
68
+ // 数据转化
69
+ list.forEach((ele, index) => {
70
+ list[index] = detailDataType(ele, dataType)
71
+ })
72
+ if (ARRAY_LIST.includes(type) && validatenull(list) && alone) list = ['']
73
+ } else {
74
+ list = detailDataType(list, dataType)
75
+ }
76
+ return list
77
+ }
78
+
79
+ /**
80
+ * 搜索框获取动态组件
81
+ */
82
+ export const getSearchType = (column) => {
83
+ const type = column.type
84
+ const range = column.searchRange
85
+ let result = type
86
+ if (column.searchType) return column.searchType
87
+ if (['radio', 'checkbox', 'switch'].includes(type)) {
88
+ result = 'select'
89
+ } else if (DATE_LIST.includes(type)) {
90
+ const rangeKey = 'range'
91
+ if (range) {
92
+ if (!type.includes(rangeKey)) {
93
+ result = type + rangeKey
94
+ } else {
95
+ result = type
96
+ }
97
+ } else result = type.replace(rangeKey, '')
98
+ } else if (['textarea'].includes(type)) {
99
+ result = 'input'
100
+ }
101
+ return result
102
+ }
103
+
104
+ /**
105
+ * 动态获取组件
106
+ */
107
+ export const getComponent = (type, component) => {
108
+ let result = type || 'input'
109
+ if (!validatenull(component)) {
110
+ return component
111
+ } else if (ARRAY_LIST.includes(type)) {
112
+ result = 'array'
113
+ } else if (['time', 'timerange'].includes(type)) {
114
+ result = 'time'
115
+ } else if (DATE_LIST.includes(type)) {
116
+ result = 'date'
117
+ } else if (['password', 'textarea', 'search'].includes(type)) {
118
+ result = 'input'
119
+ } else if (INPUT_LIST.includes(type)) {
120
+ result = `input-${type}`
121
+ }
122
+ return KEY_COMPONENT_NAME + result
123
+ }
124
+
125
+ /**
126
+ * 表格初始化值
127
+ */
128
+
129
+ export const formInitVal = (list = []) => {
130
+ let tableForm = {}
131
+ list.forEach((ele) => {
132
+ // ARRAY_VALUE_LIST.includes(ele.type) || (MULTIPLE_LIST.includes(ele.type) && ele.multiple) || ele.dataType === 'array' 只有数据类型为array的才为数组
133
+ if (ele.dataType === 'array') {
134
+ tableForm[ele.prop] = []
135
+ } else if (RANGE_LIST.includes(ele.type) && ele.range == true) {
136
+ tableForm[ele.prop] = [0, 0]
137
+ } else if (['rate', 'slider', 'number'].includes(ele.type) || ele.dataType === 'number') {
138
+ tableForm[ele.prop] = undefined
139
+ } else {
140
+ tableForm[ele.prop] = ''
141
+ }
142
+ if (ele.bind) {
143
+ tableForm = createObj(tableForm, ele.bind)
144
+ }
145
+ // 表单默认值设置
146
+ if (!validatenull(ele.value)) {
147
+ tableForm[ele.prop] = ele.value
148
+ }
149
+ })
150
+ return tableForm
151
+ }
152
+
153
+ export const getPlaceholder = function (column, type) {
154
+ const placeholder = column.placeholder
155
+ const label = column.label
156
+ if (type === 'search') {
157
+ const searchPlaceholder = column.searchPlaceholder
158
+ if (!validatenull(searchPlaceholder)) {
159
+ return searchPlaceholder
160
+ } else {
161
+ return label
162
+ }
163
+ } else if (validatenull(placeholder)) {
164
+ if (SELECT_LIST.includes(column.type)) {
165
+ return `${t('tip.select')} ${label}`
166
+ } else {
167
+ return `${t('tip.input')} ${label}`
168
+ }
169
+ }
170
+
171
+ return placeholder
172
+ }
@@ -0,0 +1,57 @@
1
+ import dayjs from 'dayjs'
2
+ import { ARRAY_VALUE_LIST, DATE_LIST, DIC_SHOW_SPLIT, DIC_SPLIT, MULTIPLE_LIST } from '/@/utils/avue/global/variable.js'
3
+ import { detailDataType, getAsVal, getDicValue, getPasswordChar } from '/@/utils/avue/utils/util.js'
4
+ import { validatenull } from '/@/utils/avue/utils/validate.js'
5
+ export const detail = (row = {}, column = {}, option = {}, dic = []) => {
6
+ let result = row[column.prop]
7
+ const type = column.type
8
+ const separator = column.separator
9
+ // 深结构绑定处理
10
+ if (column.bind) result = getAsVal(row, column.bind)
11
+ if (!validatenull(result)) {
12
+ const selectFlag = MULTIPLE_LIST.includes(column.type) && column.multiple
13
+ const arrayFlag = ARRAY_VALUE_LIST.includes(column.type)
14
+ if ((selectFlag || arrayFlag) && !Array.isArray(result) && !column.dataType) column.dataType = 'string'
15
+ if (column.dataType) {
16
+ if (selectFlag || arrayFlag) {
17
+ if (!Array.isArray(result)) result = result.split(separator || DIC_SPLIT)
18
+ result.forEach((ele) => {
19
+ ele = detailDataType(ele, column.dataType)
20
+ })
21
+ } else {
22
+ result = detailDataType(result, column.dataType)
23
+ }
24
+ }
25
+ if ('password' === type) {
26
+ result = getPasswordChar(result, '*')
27
+ } else if (DATE_LIST.includes(type) && column.format) {
28
+ const format = column.format
29
+ const formatValue = dayjs().format('YYYY-MM-DD')
30
+ if (type.indexOf('range') !== -1) {
31
+ let date1 = result[0] || '',
32
+ date2 = result[1] || ''
33
+ if (type === 'timerange' && date1.length <= 8 && date2.length < 8) {
34
+ date1 = `${formatValue} ${date1}`
35
+ date2 = `${formatValue} ${date2}`
36
+ }
37
+ result = [dayjs(date1).format(format), dayjs(date2).format(format)].join(column.separator || '~')
38
+ } else {
39
+ if (type === 'time' && result.length <= 8) {
40
+ result = `${formatValue} ${result}`
41
+ }
42
+ result = dayjs(result).format(format)
43
+ }
44
+ }
45
+ }
46
+ // 字典处理
47
+ if (!validatenull(dic)) {
48
+ result = getDicValue(dic, result, column.props || option.props)
49
+ }
50
+ // 自定义格式化
51
+ if (typeof column.formatter === 'function') {
52
+ result = column.formatter(row, row[column.prop], result, column)
53
+ } else if (Array.isArray(result) && !validatenull(dic)) {
54
+ result = result.join(separator || DIC_SHOW_SPLIT)
55
+ }
56
+ return result
57
+ }
@@ -0,0 +1,203 @@
1
+ import http from '/@/api/http'
2
+ import { DIC_PROPS } from '/@/utils/avue/global/variable.js'
3
+ import { getObjValue } from '/@/utils/avue/utils/util'
4
+ import { detailDataType, getAsVal } from '/@/utils/avue/utils/util.js'
5
+ const key = 'key'
6
+ function getDataType(list = [], props = {}, type) {
7
+ const valueKey = props.value || DIC_PROPS.value
8
+ const childrenKey = props.children || DIC_PROPS.children
9
+ list.forEach((ele) => {
10
+ ele[valueKey] = detailDataType(ele[valueKey], type)
11
+ if (ele[childrenKey]) getDataType(ele[childrenKey], props, type)
12
+ })
13
+ return list
14
+ }
15
+
16
+ function getResData(data, props, dataType) {
17
+ const bind = props.res
18
+ let res = data
19
+ const deep = data.data
20
+ if (bind) {
21
+ res = getAsVal(res, bind)
22
+ } else if (deep) {
23
+ res = Array.isArray(deep) ? deep : [deep]
24
+ }
25
+ if (dataType) res = getDataType(res, props, dataType)
26
+ return res
27
+ }
28
+ export const loadCascaderDic = (columnOption, safe) => {
29
+ return new Promise((resolve) => {
30
+ const list = []
31
+ const result = {}
32
+ const columnList = columnOption.filter((ele) => ele.parentProp)
33
+ safe.data.forEach((ele, index) => {
34
+ if (!safe.cascaderDIC[index]) safe.cascaderDIC[index] = {}
35
+ columnList.forEach((column) => {
36
+ if (column.hide !== true && column.dicFlag !== false) {
37
+ list.push(
38
+ new Promise((resolve) => {
39
+ if (ele[column.parentProp]) {
40
+ sendDic({
41
+ url: column.dicUrl,
42
+ props: column.props,
43
+ method: column.dicMethod,
44
+ headers: column.dicHeaders,
45
+ formatter: column.dicFormatter,
46
+ query: column.dicQuery,
47
+ dataType: column.dataType,
48
+ form: ele,
49
+ value: ele[column.parentProp],
50
+ }).then((res) => {
51
+ const obj = {
52
+ prop: column.prop,
53
+ data: res,
54
+ index: index,
55
+ }
56
+ safe.cascaderDIC[index][obj.prop] = obj.data
57
+ resolve(obj)
58
+ })
59
+ } else {
60
+ const obj = {
61
+ prop: column.prop,
62
+ data: [],
63
+ index: index,
64
+ }
65
+ safe.cascaderDIC[index][obj.prop] = obj.data
66
+ resolve(obj)
67
+ }
68
+ })
69
+ )
70
+ }
71
+ })
72
+ })
73
+ Promise.all(list).then((data) => {
74
+ data.forEach((ele) => {
75
+ if (!result[ele.index]) result[ele.index] = {}
76
+ result[ele.index][ele.prop] = ele.data
77
+ })
78
+ resolve(result)
79
+ })
80
+ })
81
+ }
82
+ export const loadDic = (option, safe) => {
83
+ return new Promise((resolve) => {
84
+ const list = [],
85
+ result = {}
86
+ let notList = [],
87
+ nameList = [],
88
+ column = option.column || []
89
+ column.forEach((ele) => {
90
+ const url = ele.dicUrl
91
+ const prop = ele.prop
92
+ const parentProp = ele.parentProp
93
+ notList = notList.concat(ele.cascader || [])
94
+ const flag = ele.dicFlag === false || ele.lazy === true || notList.includes(prop)
95
+ if (url && !parentProp && !flag) {
96
+ list.push(
97
+ new Promise((resolve) => {
98
+ sendDic({
99
+ url: url,
100
+ name: prop,
101
+ method: ele.dicMethod,
102
+ headers: ele.dicHeaders,
103
+ formatter: ele.dicFormatter,
104
+ props: ele.props,
105
+ dataType: ele.dataType,
106
+ query: ele.dicQuery,
107
+ }).then((res) => {
108
+ safe.DIC[prop] = res
109
+ resolve(res)
110
+ })
111
+ })
112
+ )
113
+ }
114
+ })
115
+ Promise.all(list).then((res) => {
116
+ nameList.forEach((ele, index) => {
117
+ result[ele] = res[index]
118
+ })
119
+ resolve(result)
120
+ })
121
+ })
122
+ }
123
+
124
+ export const loadLocalDic = (option, safe) => {
125
+ const columnData = {}
126
+ const optionData = option.dicData || {}
127
+ option.column.forEach((ele) => {
128
+ if (ele.dicData) columnData[ele.prop] = getDataType(ele.dicData, ele.props, ele.dataType)
129
+ })
130
+ const result = { ...optionData, ...columnData }
131
+ Object.keys(result).forEach((ele) => {
132
+ safe.DIC[ele] = result[ele]
133
+ })
134
+ return result
135
+ }
136
+
137
+ export const sendDic = (params) => {
138
+ let { url, query, method, resKey, props, formatter, headers = {}, value = '', column, form = {} } = params
139
+ if (column) {
140
+ url = column.dicUrl
141
+ method = column.dicMethod
142
+ headers = column.headers || {}
143
+ query = column.dicQuery || {}
144
+ formatter = column.dicFormatter
145
+ props = column.props
146
+ }
147
+ const key = 'key'
148
+ url = url || ''
149
+ let list = []
150
+ const data = {}
151
+ list = url.match(/[^\{\}]+(?=\})/g) || []
152
+ list.forEach((ele) => {
153
+ const eleKey = `{{${ele}}}`
154
+ const eleValue = form[ele]
155
+ if (ele === key) url = url.replace(eleKey, value)
156
+ else url = url.replace(eleKey, eleValue)
157
+ })
158
+ if (method === 'post') {
159
+ list = Object.keys(query)
160
+ list.forEach((ele) => {
161
+ const eleKey = query[ele]
162
+ if (typeof eleKey == 'string') {
163
+ if (eleKey.match(/\{{|}}/g)) {
164
+ const eleValue = form[eleKey.replace(/\{{|}}/g, '')]
165
+ data[ele] = eleValue
166
+ } else {
167
+ data[ele] = eleKey
168
+ }
169
+ } else {
170
+ data[ele] = eleKey
171
+ }
172
+ })
173
+ }
174
+
175
+ if (props) resKey = (props || {}).res || resKey
176
+ return new Promise((resolve) => {
177
+ const callback = (res) => {
178
+ let list = []
179
+ if (typeof formatter === 'function') {
180
+ list = formatter(res)
181
+ } else {
182
+ list = getObjValue(res, resKey)
183
+ }
184
+ resolve(list)
185
+ }
186
+
187
+ if (method === 'post') {
188
+ http({
189
+ url: url,
190
+ method: 'post',
191
+ data: data,
192
+ }).then((res) => {
193
+ callback(res)
194
+ })
195
+ } else {
196
+ http({
197
+ url: url,
198
+ }).then((res) => {
199
+ callback(res)
200
+ })
201
+ }
202
+ })
203
+ }
@@ -0,0 +1,154 @@
1
+ import { initVal } from '~/packages/core/common/dataformat.js'
2
+ import { findNode } from '/@/utils/avue/utils/util.js'
3
+
4
+ export default function () {
5
+ return {
6
+ methods: {
7
+ bindEvent(name, params) {
8
+ // console.log('bindEvent', this)
9
+ const item = findNode(this.dic, this.props, this.text)
10
+ params = Object.assign(params, { column: this.column, dic: this.dic, item }, this.tableData)
11
+ if (typeof this[name] === 'function') {
12
+ if (name == 'change') {
13
+ if (this.column.cell != true) {
14
+ this[name](params)
15
+ }
16
+ } else {
17
+ this[name](params)
18
+ }
19
+ }
20
+ this.$emit(name, params)
21
+ },
22
+ initVal() {
23
+ this.stringMode = typeof this.modelValue == 'string'
24
+ this.text = initVal(this.modelValue, this)
25
+ },
26
+ getLabelText(item) {
27
+ if (this.validatenull(item)) return ''
28
+ if (typeof this.typeformat === 'function') {
29
+ return this.typeformat(item, this.labelKey, this.valueKey)
30
+ }
31
+ return item[this.labelKey]
32
+ },
33
+ handleFocus(event) {
34
+ // console.info('handleFocus', event)
35
+ this.bindEvent('focus', { value: this.modelValue, event })
36
+ },
37
+ handleBlur(event) {
38
+ // console.info('handleBlur', event)
39
+ this.bindEvent('blur', { value: this.modelValue, event })
40
+ },
41
+ handleClick(event) {
42
+ // console.info('handleClick', event)
43
+ this.bindEvent('click', { value: this.modelValue, event })
44
+ },
45
+ handleChange(value) {
46
+ //console.info('handleChange', value)
47
+ let result = value
48
+ const flag = this.isString || this.isNumber || this.stringMode || this.listType === 'picture-img'
49
+ if (flag && Array.isArray(value)) result = value.join(this.separator)
50
+ this.bindEvent('change', { value: result })
51
+ this.$emit('update:modelValue', result)
52
+ },
53
+
54
+ Getimg(img) {
55
+ if (img.startsWith('http')) {
56
+ return img
57
+ } else {
58
+ return configJson.baseUrl + img
59
+ }
60
+ },
61
+
62
+ GetVideo(img) {
63
+ if (img.startsWith('http')) {
64
+ return img
65
+ } else {
66
+ return configJson.baseUrl + img
67
+ }
68
+ },
69
+ Getstyle(StyleData, defaultstyle = '') {
70
+ // console.info(StyleData, defaultstyle, 'qqq111')
71
+ if (typeof StyleData === 'string') {
72
+ if (StyleData == '') {
73
+ return defaultstyle
74
+ }
75
+ StyleData = JSON.parse(StyleData)
76
+ }
77
+
78
+ let styleT = ''
79
+ for (const key in StyleData) {
80
+ switch (key) {
81
+ case 'fontfamily': //字体
82
+ styleT += `font-family:${StyleData[key]};`
83
+ break
84
+ case 'fontweight': //自重
85
+ styleT += `font-weight:${StyleData[key]};`
86
+ break
87
+ case 'fontsize': //大小
88
+ styleT += `font-size:${StyleData[key]}px;`
89
+ break
90
+ case 'color': //大小
91
+ styleT += `color:${StyleData[key]};`
92
+ break
93
+ case 'height': //高
94
+ styleT += `height:${StyleData[key]};`
95
+ break
96
+ case 'width': //宽
97
+ styleT += `width:${StyleData[key]};`
98
+ break
99
+ case 'max-width': //最大宽度
100
+ styleT += `max-width:${StyleData[key]};`
101
+ break
102
+ case 'min-width': //最小宽度
103
+ styleT += `min-width:${StyleData[key]};`
104
+ break
105
+ case 'textalign': //布局
106
+ styleT += `text-align:${StyleData[key]};`
107
+ break
108
+ case 'float': //浮动
109
+ styleT += `float:${StyleData[key]};`
110
+ break
111
+ case 'borderradius': //园角
112
+ styleT += `border-radius:${StyleData[key]}px;`
113
+ break
114
+ case 'paddingtop': //padding
115
+ styleT += `padding-top:${StyleData[key]}px;`
116
+ break
117
+ case 'paddingright': //padding
118
+ styleT += `padding-right:${StyleData[key]}px;`
119
+ break
120
+ case 'paddingbottom': //padding
121
+ styleT += `padding-bottom:${StyleData[key]}px;`
122
+ break
123
+ case 'paddingleft': //padding
124
+ styleT += `padding-left:${StyleData[key]}px;`
125
+ break
126
+ case 'margintop': //padding
127
+ styleT += `margin-top:${StyleData[key]}px;`
128
+ break
129
+ case 'marginright': //padding
130
+ styleT += `margin-right:${StyleData[key]}px;`
131
+ break
132
+ case 'marginbottom': //padding
133
+ styleT += `margin-bottom:${StyleData[key]}px;`
134
+ break
135
+ case 'marginleft': //padding
136
+ styleT += `margin-left:${StyleData[key]}px;`
137
+ break
138
+ case 'backgroundcolor': //背景色
139
+ styleT += `background-color:${StyleData[key]};`
140
+ break
141
+ case 'backgroundimage': //大小
142
+ styleT += `background-image:url(${StyleData[key]});`
143
+ break
144
+ case 'QiTaYangShi': //大小
145
+ styleT += `${StyleData[key]};`
146
+ break
147
+ }
148
+ }
149
+ // console.info(styleT)
150
+ return styleT
151
+ },
152
+ },
153
+ }
154
+ }