Browse Source

add: 新增form相关组件封装

刘洋 3 years ago
parent
commit
1dd00c1fd2

+ 7 - 0
2022/aiot-evaluate/src/components/form/IpuCascader.vue

@ -0,0 +1,7 @@
1
<template>
2
  <el-cascader class="ipu-cascader"></el-cascader>
3
</template>
4
5
<script setup></script>
6
7
<style scoped lang="scss"></style>

+ 7 - 0
2022/aiot-evaluate/src/components/form/IpuCheckBox.vue

@ -0,0 +1,7 @@
1
<template>
2
  <el-checkbox class="ipu-checkbox"></el-checkbox>
3
</template>
4
5
<script setup></script>
6
7
<style scoped lang="scss"></style>

+ 7 - 0
2022/aiot-evaluate/src/components/form/IpuDatePicker.vue

@ -0,0 +1,7 @@
1
<template>
2
  <el-date-picker class="ipu-date-picker"></el-date-picker>
3
</template>
4
5
<script setup></script>
6
7
<style scoped lang="scss"></style>

+ 86 - 0
2022/aiot-evaluate/src/components/form/IpuForm.vue

@ -0,0 +1,86 @@
1
<template>
2
  <el-form>
3
    <template v-for="(form, index) in forms" :key="form?.name || index">
4
      <el-form-item
5
        :prop="form?.name || ''"
6
        :label="form?.label || ''"
7
        :rules="form?.rules || []"
8
      >
9
        <!-- input --->
10
        <ipu-input
11
          v-if="form?.type === 'input'"
12
          v-model="form.value"
13
          :width="form?.width"
14
          v-bind="form?.attrs"
15
        >
16
        </ipu-input>
17
18
        <!-- select --->
19
        <ipu-select
20
          v-if="form?.type === 'select'"
21
          v-model="form.value"
22
          :width="form?.width"
23
          v-bind="form?.attrs"
24
        >
25
        </ipu-select>
26
27
        <!-- radio --->
28
        <ipu-radio
29
          v-if="form?.type === 'radio'"
30
          v-model="form.value"
31
          :width="form?.width"
32
          v-bind="form?.attrs"
33
        ></ipu-radio>
34
35
        <!-- cascader --->
36
        <ipu-cascader
37
          v-if="form?.type === 'cascader'"
38
          v-model="form.value"
39
          :width="form?.width"
40
          v-bind="form?.attrs"
41
        ></ipu-cascader>
42
43
        <!-- switch --->
44
        <ipu-switch
45
          v-if="form?.type === 'switch'"
46
          v-model="form.value"
47
          :width="form?.width"
48
          v-bind="form?.attrs"
49
        ></ipu-switch>
50
51
        <!-- checkbox --->
52
        <ipu-checkbox
53
          v-if="form?.type === 'checkbox'"
54
          v-model="form.value"
55
          :width="form?.width"
56
          v-bind="form?.attrs"
57
        ></ipu-checkbox>
58
59
        <!-- date-picker --->
60
        <ipu-date-picker
61
          v-if="form?.type === 'date-picker'"
62
          v-model="form.value"
63
          :width="form?.width"
64
          v-bind="form?.attrs"
65
        ></ipu-date-picker>
66
      </el-form-item>
67
    </template>
68
    <el-form-item>
69
      <slot name="btns"></slot>
70
    </el-form-item>
71
  </el-form>
72
</template>
73
74
<script setup>
75
import { defineProps } from 'vue';
76
const props = defineProps({
77
  forms: {
78
    type: Array,
79
    default: () => []
80
  }
81
});
82
83
// 校验规则
84
</script>
85
86
<style lang="scss" scoped></style>

+ 7 - 0
2022/aiot-evaluate/src/components/form/IpuInput.vue

@ -0,0 +1,7 @@
1
<template>
2
  <el-input class="ipu-input" v-bind="$attrs"></el-input>
3
</template>
4
5
<script setup></script>
6
7
<style scoped lang="scss"></style>

+ 7 - 0
2022/aiot-evaluate/src/components/form/IpuRadio.vue

@ -0,0 +1,7 @@
1
<template>
2
  <el-radio class="ipu-radio"></el-radio>
3
</template>
4
5
<script setup></script>
6
7
<style scoped lang="scss"></style>

+ 21 - 0
2022/aiot-evaluate/src/components/form/IpuSelect.vue

@ -0,0 +1,21 @@
1
<template>
2
  <el-select class="ipu-select">
3
    <el-option
4
      v-for="item in options"
5
      :key="item.value"
6
      :label="item.label"
7
      :value="item.value"
8
    />
9
  </el-select>
10
</template>
11
12
<script setup>
13
const props = defineProps({
14
  options: {
15
    type: Array,
16
    default: () => []
17
  }
18
});
19
</script>
20
21
<style scoped lang="scss"></style>

+ 7 - 0
2022/aiot-evaluate/src/components/form/IpuSwitch.vue

@ -0,0 +1,7 @@
1
<template>
2
  <el-switch class="ipu-switch"> </el-switch>
3
</template>
4
5
<script setup></script>
6
7
<style scoped lang="scss"></style>

+ 7 - 0
2022/aiot-evaluate/src/components/form/IpuUpload.vue

@ -0,0 +1,7 @@
1
<template>
2
  <el-upload class="ipu-upload"></el-upload>
3
</template>
4
5
<script setup></script>
6
7
<style scoped lang="scss"></style>

+ 20 - 0
2022/aiot-evaluate/src/components/index.js

@ -1,4 +1,13 @@
1 1
import IpuTable from './table/index.vue';
2
import IpuInput from './form/IpuInput.vue';
3
import IpuSelect from './form/IpuSelect.vue';
4
import IpuRadio from './form/IpuRadio.vue';
5
import IpuCascader from './form/IpuCascader.vue';
6
import IpuSwitch from './form/IpuSwitch.vue';
7
import IpuCheckBox from './form/IpuCheckBox.vue';
8
import IpuDatePicker from './form/IpuDatePicker.vue';
9
import IpuForm from './form/IpuForm.vue';
10
import IpuSearch from './search-params/index.vue';
2 11
3 12
/**
4 13
 * 注册全局组件
@ -7,4 +16,15 @@ import IpuTable from './table/index.vue';
7 16
export function setupGlobalComponents(app) {
8 17
  // 通用普通表格
9 18
  app.component('ipu-table', IpuTable);
19
  // 表单元素
20
  app.component('ipu-input', IpuInput);
21
  app.component('ipu-select', IpuSelect);
22
  app.component('ipu-radio', IpuRadio);
23
  app.component('ipu-cascader', IpuCascader);
24
  app.component('ipu-switch', IpuSwitch);
25
  app.component('ipu-checkbox', IpuCheckBox);
26
  app.component('ipu-date-picker', IpuDatePicker);
27
  app.component('ipu-form', IpuForm);
28
  // 搜索模块
29
  app.component('ipu-search', IpuSearch);
10 30
}

+ 118 - 0
2022/aiot-evaluate/src/components/search-params/index.vue

@ -0,0 +1,118 @@
1
<template>
2
  <div class="search-params">
3
    <ipu-form :inline="true" :model="formValues" :forms="searchParams">
4
      <template v-slot:btns>
5
        <div class="btns">
6
          <el-button @click.stop="search" type="primary">搜索</el-button>
7
          <el-button @click.stop="clearSearch">清除</el-button>
8
        </div>
9
      </template>
10
    </ipu-form>
11
    <div class=""></div>
12
  </div>
13
</template>
14
15
<script setup>
16
import { defineProps, defineEmits } from 'vue';
17
const emits = defineEmits(['search', 'clearSearch']);
18
19
const props = defineProps({
20
  searchParams: {
21
    type: Array,
22
    default: () => []
23
  },
24
  formValues: {
25
    type: Object,
26
    default: () => {}
27
  }
28
});
29
30
// 处理 input
31
const parseInput = (param) => {
32
  if (param?.type === 'input') {
33
    return { [param?.name]: param.value };
34
  }
35
};
36
// 处理 select
37
const parseSelect = (param) => {
38
  if (param?.type === 'select') {
39
    return { [param?.name]: param.value };
40
  }
41
};
42
// 处理 radio
43
const parseRadio = (param) => {
44
  if (param?.type === 'radio') {
45
    return { [param?.name]: param.value };
46
  }
47
};
48
// 处理 cascader
49
const parseCascader = (param) => {
50
  if (param?.type === 'cascader') {
51
    return { [param?.name]: param.value };
52
  }
53
};
54
// 处理 switch
55
const parseSwitch = (param) => {
56
  if (param?.type === 'switch') {
57
    return { [param?.name]: param.value };
58
  }
59
};
60
// 处理 checkbox
61
const parseCheckbox = (param) => {
62
  if (param?.type === 'switch') {
63
    return { [param?.name]: param.value };
64
  }
65
};
66
const parseParam = (param, isClear = false) => {
67
  // console.log(parseInput(param));
68
  return (
69
    parseInput(param, isClear) ||
70
    parseSelect(param, isClear) ||
71
    parseRadio(param, isClear) ||
72
    parseCascader(param, isClear) ||
73
    parseSwitch(param, isClear) ||
74
    parseCheckbox(param, isClear)
75
  );
76
};
77
// 处理date-picker
78
79
// 搜搜项处理
80
const parseSearch = () => {
81
  const params = JSON.parse(JSON.stringify(props?.searchParams));
82
  let obj = {};
83
  if (params?.length) {
84
    params.forEach((param) => {
85
      obj = { ...obj, ...parseParam(param) };
86
    });
87
  }
88
  return obj;
89
};
90
// 清除搜索
91
const clearSearch = () => {
92
  props?.searchParams.map((param) => {
93
    const dataType = Object.prototype.toString.call(param.value);
94
    switch (dataType) {
95
    case '[object String]':
96
      param.value = '';
97
      break;
98
    case '[object Array]':
99
      param.value = [];
100
      break;
101
    case '[object Object]':
102
      param.value = {};
103
      break;
104
    default:
105
      param.value = undefined;
106
      break;
107
    }
108
  });
109
  emits('clearSearch', parseSearch());
110
};
111
112
// 搜索
113
const search = () => {
114
  emits('search', parseSearch());
115
};
116
</script>
117
118
<style scoped lang="scss"></style>

+ 13 - 0
2022/aiot-evaluate/src/components/table-module/index.vue

@ -0,0 +1,13 @@
1
<template>
2
  <div class="table-module">
3
4
  </div>
5
</template>
6
7
<script setup>
8
9
</script>
10
11
<style scoped lang="scss">
12
13
</style>

+ 14 - 0
2022/aiot-evaluate/src/utils/verification.js

@ -0,0 +1,14 @@
1
const verifications = {
2
  input: {
3
    tel: '/^((0d{2,3}-d{7,8})|(1[34578]d{9}))$/',
4
    ID: '/(^d{15}$)|(^d{18}$)|(^d{17}(d|X|x)$)/',
5
    email: '/^([a-zA-Z0-9]+[-_.]?)+@[a-zA-Z0-9]+.[a-z]+$/',
6
    int: '/^-?[1-9]d*$/',
7
    pos_int: '/^[1-9]d*$/',
8
    low_letters: '/^[a-z]+$/',
9
    upper_letters: '/^[A-Z]+$/',
10
    letters: '/^[A-Za-z]+$/',
11
    chinese: '/^[\u0391-\uFFE5A-Za-z]+$/',
12
    letters_num: '/^[a-zA-Z0-9]+$/'
13
  }
14
};

+ 98 - 35
2022/aiot-evaluate/src/views/demos/ApiResourceManagement.vue

@ -11,35 +11,18 @@
11 11
  <!-- 表体 -->
12 12
  <div class="form-body">
13 13
    <!-- 搜索 -->
14
    <el-row class="search">
15
      <el-col :span="7">
16
        <span>资源名称:</span>
17
        <el-input v-model="inputSearch" placeholder="请输入" />
18
      </el-col>
19
      <el-col :span="7">
20
        <span>所属应用:</span>
21
        <el-select v-model="ruleForm.role" placeholder="请选择">
22
          <el-option label="终端柜管理角色" value="终端柜管理角色" />
23
          <el-option label="告警管理角色" value="告警管理角色" />
24
          <el-option label="边缘管理角色" value="边缘管理角色" />
25
          <el-option label="设备管理角色" value="设备管理角色" />
26
        </el-select>
27
      </el-col>
28
      <el-col :span="10">
29
        <el-button type="primary">查询</el-button>
30
        <el-button>重置</el-button>
31
      </el-col>
32
    </el-row>
14
    <ipu-search
15
      :searchParams="searchParams"
16
      :formValues="formValues"
17
      @search="search"
18
      @clearSearch="clearSearch"
19
    ></ipu-search>
33 20
34 21
    <!-- 表格 -->
35
    <ipu-table
36
      :tableHeader="tableHeader"
37
      :tableData="tableData"
38
    ></ipu-table>
22
    <ipu-table :tableHeader="tableHeader" :tableData="tableData"></ipu-table>
39 23
40 24
    <!-- 分页器 -->
41 25
    <el-row class="demo-pagination-block">
42
      <!-- currentPage-初始当前页面;pageSize-初始一页数据数;page-count-分页器最大页码按钮数,超过该数会折叠 -->
43 26
      <el-pagination
44 27
        v-model:current-page="currentPage"
45 28
        v-model:page-size="pageSize"
@ -75,20 +58,11 @@
75 58
76 59
<script setup>
77 60
import { ref, reactive } from 'vue';
78
// import { ElMessage, ElMessageBox } from "element-plus";
79 61
import CreateApplication from '@/components/dialog/CreateApplication';
80 62
import EditApplication from '@/components/dialog/EditApplication';
81 63
import DeleteData from '@/components/dialog/DeleteData';
82 64
83 65
// --------查询资源----------
84
const inputSearch = ref('');
85
const ruleForm = reactive({
86
  resourceId: '',
87
  resourceName: '',
88
  belongApplication: '',
89
  resourceType: '',
90
  role: ''
91
});
92 66
const tableHeader = ref([
93 67
  {
94 68
    label: '资源名称',
@ -126,7 +100,94 @@ const tableHeader = ref([
126 100
    width: '217'
127 101
  }
128 102
]);
103
const formValues = {
104
  resourceName: '',
105
  sourceType: [],
106
  resourceName1: ''
107
};
108
// 搜索项
109
const searchParams = ref([{
110
  name: 'resourceName',
111
  type: 'input',
112
  label: '资源名称',
113
  value: '',
114
  styles: {
115
    width: 200
116
  },
117
  attrs: {
118
    clearable: true
119
  },
120
  rules: [{
121
    required: true,
122
    message: 'Please input email address',
123
    trigger: 'blur'
124
  },
125
  {
126
    type: 'email',
127
    message: 'Please input correct email address',
128
    trigger: ['blur', 'change']
129
  }]
130
},
131
{
132
  name: 'sourceType',
133
  label: '资源类型',
134
  type: 'select',
135
  attrs: {
136
    clearable: true,
137
    disabled: false,
138
    multiple: true,
139
    options: [
140
      {
141
        label: '资源1',
142
        value: 'label'
143
      },
144
      {
145
        label: '资源2',
146
        value: 'label2'
147
      },
148
      {
149
        label: '资源3',
150
        value: 'labe3'
151
      },
152
      {
153
        label: '资源4',
154
        value: 'label4'
155
      },
156
      {
157
        label: '资源5',
158
        value: 'label5'
159
      },
160
      {
161
        label: '资源6',
162
        value: 'label6'
163
      }
164
    ]
165
  },
166
  width: 200,
167
  value: []
168
},
169
{
170
  name: 'resourceName1',
171
  type: 'input',
172
  width: 200,
173
  attrs: {
174
    disabled: true,
175
    clearable: true
176
  },
177
  label: '资源名称1',
178
  value: ''
179
}]);
129 180
181
// 搜索
182
const search = (data) => {
183
  console.log(data);
184
  console.log('开始搜索');
185
};
186
// 清除搜索
187
const clearSearch = (data) => {
188
  console.log('清除');
189
  search(data);
190
};
130 191
// -------分页器---------
131 192
const pageSize = ref(10);
132 193
const currentPage = ref(1);
@ -285,10 +346,12 @@ const rowIndex = ref(null);
285 346
function dataOperation(val, operation) {
286 347
  // val<boolean>:控制弹窗显隐;   operation<number>:0 - 取消删除;  1- 确认删除
287 348
  visibleDel.value = val;
288
  if (operation === 1) { tableData.splice(rowIndex, 1); }
349
  if (operation === 1) {
350
    tableData.splice(rowIndex, 1);
351
  }
289 352
}
290 353
</script>
291 354
292 355
<style lang="scss" scoped>
293
@import "@/assets/styles/index.scss";
356
@import '@/assets/styles/index.scss';
294 357
</style>