Browse Source

补充示例

develop
zq 3 weeks ago
parent
commit
4fb4e724e6
  1. 16
      examples/package-lock.json
  2. 2
      examples/package.json
  3. 50
      examples/src/App.vue
  4. 1
      examples/src/main.js
  5. 2
      packages/GuipRadio/src/index.vue
  6. 2
      packages/GuipTable/src/index.vue
  7. 6
      packages/SearchInput/index.js
  8. 19
      packages/SearchInput/src/index.scss
  9. 212
      packages/SearchInput/src/index.vue
  10. 4
      packages/index.js

16
examples/package-lock.json

@ -8,7 +8,7 @@
"name": "examples",
"version": "1.0.0",
"dependencies": {
"@zhicheng1012/zhicheng-components": "^1.0.18",
"@zhicheng1012/zhicheng-components": "^1.0.28",
"core-js": "^3.40.0",
"element-ui": "^2.15.14",
"my-components": "file:../",
@ -30,7 +30,7 @@
},
"..": {
"name": "@zhicheng1012/zhicheng-components",
"version": "1.0.26",
"version": "1.0.28",
"license": "MIT",
"dependencies": {
"async-validator": "^1.11.5",
@ -3219,9 +3219,9 @@
"integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ=="
},
"node_modules/@zhicheng1012/zhicheng-components": {
"version": "1.0.26",
"resolved": "https://registry.npmjs.org/@zhicheng1012/zhicheng-components/-/zhicheng-components-1.0.26.tgz",
"integrity": "sha512-An3vGczA7RMaJM+HG/SUWknSzLtG5+orG4ZK1Bl5O/PxQbvcXqlO6zLfXGO2qJ1mkD8568PrM9cg69fdMsrr/A==",
"version": "1.0.28",
"resolved": "https://registry.npmjs.org/@zhicheng1012/zhicheng-components/-/zhicheng-components-1.0.28.tgz",
"integrity": "sha512-tGSghb1s4owO4oxi7DEHnzZZhxXOX7pfYF+4Phczv+4w3D1/3X9I6zWZkPgcKMq6qIBtqrJazZQMr9pyml2jZQ==",
"dependencies": {
"async-validator": "^1.11.5",
"core-js": "^3.40.0",
@ -19501,9 +19501,9 @@
"integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ=="
},
"@zhicheng1012/zhicheng-components": {
"version": "1.0.26",
"resolved": "https://registry.npmjs.org/@zhicheng1012/zhicheng-components/-/zhicheng-components-1.0.26.tgz",
"integrity": "sha512-An3vGczA7RMaJM+HG/SUWknSzLtG5+orG4ZK1Bl5O/PxQbvcXqlO6zLfXGO2qJ1mkD8568PrM9cg69fdMsrr/A==",
"version": "1.0.28",
"resolved": "https://registry.npmjs.org/@zhicheng1012/zhicheng-components/-/zhicheng-components-1.0.28.tgz",
"integrity": "sha512-tGSghb1s4owO4oxi7DEHnzZZhxXOX7pfYF+4Phczv+4w3D1/3X9I6zWZkPgcKMq6qIBtqrJazZQMr9pyml2jZQ==",
"requires": {
"async-validator": "^1.11.5",
"core-js": "^3.40.0",

2
examples/package.json

@ -9,7 +9,7 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"@zhicheng1012/zhicheng-components": "^1.0.18",
"@zhicheng1012/zhicheng-components": "^1.0.28",
"core-js": "^3.40.0",
"element-ui": "^2.15.14",
"my-components": "file:../",

50
examples/src/App.vue

@ -33,6 +33,17 @@
</PromptText>
</section>
<section class="demo-section">
<h2>状态标签</h2>
<div class="ele-item gap12" id="example4">
<div class="status-item divgreen"><span class="fontgreen">状态标签</span></div>
<div class="status-item divorange"><span class="fontorange">状态标签</span></div>
<div class="status-item divgray"><span class="fontgray">状态标签</span></div>
<div class="status-item divred"><span class="fontred">状态标签</span></div>
<div class="status-item divblue"><span class="fontblue">状态标签</span></div>
</div>
</section>
<section class="demo-section">
<h2>按钮组件集合</h2>
<div class="ele-item">
<label for="">按钮尺寸</label>
@ -50,21 +61,32 @@
<GuipButton disabled>按钮</GuipButton>
</div>
<div class="ele-item">
<label for="">弱按钮</label>
<GuipButton type="ignore">按钮</GuipButton>
<GuipButton type="ignore" loading>按钮</GuipButton>
<GuipButton type="ignore" disabled>按钮</GuipButton>
<label for="">ignore</label>
<GuipButton type="ignore">按钮</GuipButton>
<GuipButton type="ignore" loading>按钮</GuipButton>
<GuipButton type="ignore" disabled>按钮</GuipButton>
</div>
<div class="ele-item">
<label for="">中按钮</label>
<GuipButton type="system">按钮</GuipButton>
<GuipButton type="system" loading>按钮</GuipButton>
<GuipButton type="system" disabled>按钮</GuipButton>
<label for="">system</label>
<GuipButton type="system">按钮</GuipButton>
<GuipButton type="system" loading>按钮</GuipButton>
<GuipButton type="system" disabled>按钮</GuipButton>
</div>
<div class="ele-item">
<label for="">文字按钮</label>
<GuipButton type="text">强引导</GuipButton>
<GuipButton type="grey">弱引导</GuipButton>
<label for="">often</label>
<GuipButton type="often">按钮</GuipButton>
<GuipButton type="often" loading>按钮</GuipButton>
<GuipButton type="often" disabled>按钮</GuipButton>
</div>
<div class="ele-item">
<label for="">文字按钮</label>
<GuipButton type="text">强引导</GuipButton>
<GuipButton type="grey">弱引导</GuipButton>
<GuipButton type="warn">警示</GuipButton>
</div>
<div class="ele-item">
<label for="">独特按钮单独写样式</label>
<div class="btn1">创建首个网站</div>
</div>
<div class="ele-item">
<label for="">按钮套餐</label>
@ -201,8 +223,10 @@
<section class="demo-section">
<h2>表格(表头自定义自定义渲染固定列)</h2>
<GuipButton type="primary" @click="toggleAllSelection">全选按钮</GuipButton>
<GuipTable :tableData="tableData2" ref="multipleTable" @selectChange="handleSelectionChange" :multiple="true"
<el-table :data="[{name2:'22',address:'赛道'}]">
<el-table-column prop="date" label="日期" width="180"></el-table-column>
</el-table>
<GuipTable :tableData="[{name2:'22',address:'赛道'}]" ref="multipleTable" @selectChange="handleSelectionChange" :multiple="true"
autoColumn="true" :loading="tableLoading" :border="true">
<!-- <template slot="header"> -->
<el-table-column width="180" fixed="left" label="名称(固定左)"></el-table-column>

1
examples/src/main.js

@ -1,6 +1,7 @@
import Vue from 'vue/dist/vue.esm.js' // 必须用完整版
import App from './App.vue'
import ElementUI from 'element-ui';
// 用 npm包
// import ZhichengUI from '@zhicheng1012/zhicheng-components'
// import '@zhicheng1012/zhicheng-components/dist/css/zhicheng-components.css';
import 'element-ui/lib/theme-chalk/index.css' // 如果依赖Element

2
packages/GuipRadio/src/index.vue

@ -42,7 +42,7 @@
<script>
export default {
name: 'MyRadioGroup',
name: 'GuipRadio',
props: {
//
column: {

2
packages/GuipTable/src/index.vue

@ -51,7 +51,7 @@
import GuipButton from '../../GuipButton/src/index.vue';
export default {
name: 'GuipTextarea',
name: 'GuipTable',
props: ['tableData', 'loading', 'width', 'height', 'autoColumn', 'columns', 'border', 'multiple'],
data() {
return {

6
packages/SearchInput/index.js

@ -0,0 +1,6 @@
import SearchInput from './src/index.vue'
SearchInput.install = function(Vue) {
Vue.component(SearchInput.name || 'SearchInput', SearchInput)
}
export default SearchInput

19
packages/SearchInput/src/index.scss

@ -0,0 +1,19 @@
.school-auto-complete {
width: 100%;
}
.school-option {
width: 100%;
span {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
img {
width: 16px;
height: 16px;
margin-left: 8px;
}
}

212
packages/SearchInput/src/index.vue

@ -0,0 +1,212 @@
<template>
<el-autocomplete class="school-auto-complete" :value="value" :fetch-suggestions="querySearchAsync"
:placeholder="placeholder" :debounce="debounce" :loading="loading" @select="handleSelect" @input="handleInput"
@clear="handleManualClear" :clearable="clearable" :size="size" :disabled="disabled">
<!-- 自定义下拉选项 -->
<template #default="{ item }">
<div class="flex-between school-option">
<span>{{ item.name }}</span>
<img v-if="showSelectedIcon && item.id === selectedSchoolId" src="../../assets/drop-selected.svg"
alt="selected" />
</div>
</template>
</el-autocomplete>
</template>
<script>
import './index.scss'
export default {
name: 'SearchInput',
props: {
url: {
type: String,
default: ''
},
//
value: {
type: String,
default: ''
},
// ID
selectedSchoolId: {
type: [String, Number],
default: null
},
//
placeholder: {
type: String,
default: '请输入名称'
},
//
debounce: {
type: Number,
default: 300
},
//
clearable: {
type: Boolean,
default: true
},
//
size: {
type: String,
default: 'medium'
},
//
disabled: {
type: Boolean,
default: false
},
//
showSelectedIcon: {
type: Boolean,
default: true
}
},
data() {
return {
loading: false,
timeout: null,
lastSearchKeyword: '',
schoolList: [],
//
lastValidSelection: null
}
},
mounted() {
//
if (this.selectedSchoolId && this.value) {
this.lastValidSelection = {
id: this.selectedSchoolId,
name: this.value
}
}
},
beforeDestroy() {
clearTimeout(this.timeout)
},
methods: {
/**
* 异步搜索学校
*/
async querySearchAsync(queryString, callback) {
const keyword = queryString.trim()
if (!keyword || keyword === this.lastSearchKeyword) {
callback([])
return
}
this.lastSearchKeyword = keyword
this.loading = true
clearTimeout(this.timeout)
this.timeout = setTimeout(async () => {
try {
const schools = await this.searchSchools(keyword)
this.schoolList = schools
callback(schools)
} catch (error) {
console.error('搜索失败:', error)
callback([])
} finally {
this.loading = false
}
}, this.debounce)
},
/**
* 搜索学校API调用
*/
async searchSchools(keyword) {
try {
const response = await this.$http('POST', this.url, {
keyword
})
if (response.status && response.data) {
return response.data
}
return []
} catch (error) {
this.$message.error('搜索列表失败')
throw error
}
},
/**
* 处理选择事件
*/
handleSelect(item) {
console.log('选中学校:', item)
//
this.lastValidSelection = {
id: item.id,
name: item.name
}
this.$emit('select', item)
this.$emit('update:selectedSchoolId', item.id)
this.$emit('input', item.name)
this.$emit('change', item)
},
/**
* 处理输入事件 - 安全版本
*/
handleInput(value) {
console.log('输入变化:', value, '当前选中:', this.selectedSchoolId)
//
this.$emit('input', value)
//
// handleManualClear
},
handleManualClear() {
console.log('用户手动清空')
this.clearSelection()
},
clearSelection() {
console.log('执行清空操作')
this.$emit('input', '')
this.$emit('update:selectedSchoolId', null)
this.$emit('clear')
this.lastSearchKeyword = ''
this.lastValidSelection = null
},
setSelectedSchool(school) {
if (school && school.id && school.name) {
this.lastValidSelection = {
id: school.id,
name: school.name
}
this.$emit('input', school.name)
this.$emit('update:selectedSchoolId', school.id)
this.$emit('select', school)
}
},
clear() {
this.clearSelection()
},
async triggerSearch(keyword) {
return await this.searchSchools(keyword || this.value)
},
/**
* 恢复上一次的有效选择
*/
restoreLastSelection() {
if (this.lastValidSelection) {
this.setSelectedSchool(this.lastValidSelection)
}
}
}
}
</script>

4
packages/index.js

@ -14,6 +14,7 @@ import GuipSwitch from './GuipSwitch';
import GuipTooltip from './GuipToolTip';
import GuipDialog from './GuipDialog';
import GuipMessage from './GuipMessage';
import SearchInput from './SearchInput';
// import CustomDropdown from './CustomDropdown';
import GuipFormItem from './GuipFormItem';
@ -64,6 +65,7 @@ const components = [
GuipSwitch,
GuipDialog,
GuipFormItem,
SearchInput
// CustomDropdown
];
@ -109,6 +111,7 @@ export {
GuipDialog,
GuipFormItem,
GuipMessage,
SearchInput
// CustomDropdown
}
export default {
@ -130,5 +133,6 @@ export default {
GuipDialog,
GuipFormItem,
GuipMessage,
SearchInput
// CustomDropdown
}
Loading…
Cancel
Save