提交 4c482523 作者: 方治民

chore: 删除 linkedlist 示例

上级 ef8f4bfd
import { faker } from '@faker-js/faker/locale/zh_CN'
import { pinyin } from 'pinyin-pro'
export function getData() {
const data = Array(1000)
.fill(0)
.map((item) => {
const name = faker.name.fullName()
return {
id: item,
name,
phone: faker.phone.number('1###########'),
avatar: faker.image.avatar(),
unit: faker.company.name(),
checked: false,
}
})
const result = data
.map((item) => {
const props = {}
if (item.name) {
item.letter = pinyin(item.name.charAt(), { pattern: 'first' })[0].toUpperCase()
} else {
item.letter = '★'
}
return {
...item,
...props,
// TODO: 存在性能问题,需要优化后再使用
// src: item.avatar || '/static/images/me/user_default.jpg',
text: item.name,
subText: item.unit,
}
})
.reduce((prev, cur) => {
const letter = cur.letter
const index = prev.findIndex((item) => item.letter === letter)
if (index === -1) {
prev.push({
letter,
items: [cur],
})
} else {
prev[index].items.push(cur)
}
return prev
}, [])
.sort((a, b) => {
return a.letter.charCodeAt(0) - b.letter.charCodeAt(0)
})
return result
}
<template>
<view class="uni-swiper-page">
<list ref="list" class="list" :offset-accuracy="5" :bounce="false" fixFreezing="true">
<cell v-for="(item, index) in dataList" :key="item.id" :ref="'item' + index">
<view class="list-item">
<text>{{ item.name }}</text>
</view>
</cell>
<cell class="loading"></cell>
</list>
</view>
</template>
<script>
import { faker } from '@faker-js/faker/locale/zh_CN'
import { pinyin } from 'pinyin-pro'
import fuiIndexList from '../../../components/FirstUI/fui-index-list/fui-index-list.vue'
export default {
components: {
fuiIndexList,
},
props: {
pid: {
type: [Number, String],
default: '',
},
parentId: {
type: String,
default: '',
},
},
data() {
return {
scrollable: true,
dataList: [],
}
},
created() {
for (var i = 0; i < 5000; i++) {
this.dataList.push({
id: i,
// name: faker.name.lastName() + faker.name.firstName(),
name: i,
})
}
},
methods: {
getData() {
const data = Array(1000)
.fill(0)
.map((item) => {
return {
id: item,
name: faker.name.lastName() + faker.name.firstName(),
phone: faker.phone.number('1###########'),
avatar: faker.image.avatar(),
unit: faker.company.name(),
checked: false,
}
})
const result = data
.map((item) => {
const props = {}
if (item.name) {
item.letter = pinyin(item.name.charAt(), { pattern: 'first' })[0].toUpperCase()
} else {
item.letter = '★'
}
return {
...item,
...props,
// TODO: 存在性能问题,需要优化后再使用
src: item.avatar || '/static/images/me/user_default.jpg',
text: item.name,
subText: item.unit,
}
})
.reduce((prev, cur) => {
const letter = cur.letter
const index = prev.findIndex((item) => item.letter === letter)
if (index === -1) {
prev.push({
letter,
items: [cur],
})
} else {
prev[index].items.push(cur)
}
return prev
}, [])
.sort((a, b) => {
return a.letter.charCodeAt(0) - b.letter.charCodeAt(0)
})
return result
},
setScrollRef(height) {
if (this.$refs['list'].setSpecialEffects) {
this.$refs['list'].setSpecialEffects({
id: this.parentId,
headerHeight: height,
})
}
},
loadData() {
// 首次激活时被调用
},
clear() {
// 释放数据时被调用,参考 swiper-list 缓存配置
this.dataList.length = 0
},
},
}
</script>
<style scoped>
.uni-swiper-page {
flex: 1;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.list {
flex: 1;
background-color: #ebebeb;
}
.list-item {
margin-left: 12px;
margin-right: 12px;
margin-top: 12px;
padding: 20px;
background-color: #fff;
border-radius: 5px;
}
.loading {
height: 20px;
}
</style>
import { faker } from '@faker-js/faker/locale/zh_CN'
import { pinyin } from 'pinyin-pro'
export function getData() {
const data = Array(1000)
.fill(0)
.map((item) => {
return {
id: item,
name: faker.name.lastName() + faker.name.firstName(),
phone: faker.phone.number('1###########'),
avatar: faker.image.avatar(),
unit: faker.company.name(),
checked: false,
}
})
const result = data
.map((item: any) => {
const props = {}
if (item.name) {
item.letter = pinyin(item.name.charAt(), { toneType: 'none', pattern: 'first' })[0].toUpperCase()
} else {
item.letter = '#'
}
return {
...item,
...props,
// TODO: 存在性能问题,需要优化后再使用
// src: item.avatar || '/static/images/me/user_default.jpg',
text: item.name,
subText: item.unit,
}
})
.reduce((prev: any, cur: any) => {
const letter = cur.letter
const index = prev.findIndex((item: any) => item.letter === letter)
if (index === -1) {
prev.push({
letter,
items: [cur],
})
} else {
prev[index].items.push(cur)
}
return prev
}, [])
.sort((a: any, b: any) => {
return a.letter.charCodeAt(0) - b.letter.charCodeAt(0)
})
return result
}
<script setup lang="ts">
import { getData } from './data'
interface Params {
title?: string
multiple?: boolean
}
const model = reactive({
params: {} as Params,
search: '',
data: [] as Recordable[],
show: false,
buttons: [],
})
const data = computed(() => {
const list = model.data.filter((item: any) => {
item.data = model.search
? item.items.filter(
(subItem: any) =>
subItem.name?.includes(model.search) ||
subItem.unit?.includes(model.search) ||
subItem.phone?.includes(model.search),
)
: item.items
return item.data.length > 0
})
return {
list,
total: list.reduce((prev: any, cur: any) => prev + cur.data.length, 0),
}
})
onLoad(({ multiple, title }) => {
model.params.title = title
model.params.multiple = multiple === 'true'
// 自定义设置标题
if (title) {
uni.setNavigationBarTitle({ title })
}
// 获取人员列表
Message.loading('加载中...')
model.data = getData()
Message.hideLoading()
// 操作项
model.buttons = []
if (model.params.multiple) {
model.buttons.push({
name: '确定',
value: 'SUBMIT',
type: 'primary',
onClick: () => {
const result = toRaw(model.data)
.reduce((all, item) => all.concat(item.data), [])
.filter((item: any) => item.checked)
console.log('Multiple Result', result)
callback(result)
},
})
}
})
function search(e: any) {
model.search = e.detail.value || ''
}
function choose(value: any) {
if (model.params?.multiple) {
data.value.list[value.index].data[value.subIndex].checked = !value.checked
} else {
console.log('Single Result', value)
callback(value)
}
}
function callback(result: any) {
uni.$emit('chooseShootOrderReceiverUser', result)
uni.navigateBack()
}
const buttonWidth = computed(() => {
const len = model.buttons.length
return (750 - 60) / len - (len - 1) * (30 / len)
})
</script>
<template>
<view class="wrap">
<!-- -->
<fui-virtual-index-list
isSrc
:listData="data.list"
:isSelect="model.params?.multiple"
:subRight="false"
@init="model.show = true"
@click="choose"
:class="model.params?.multiple ? 'multiple' : ''"
:debug="true"
>
<fui-search-bar @input="search" @clear="model.search = ''" />
<template #footer>
<fui-loadmore v-if="!model.show" />
<fui-divider :text="`${data.total || 0}联系人`" v-if="model.show" />
<!-- 安全区 -->
<fui-safe-area />
</template>
</fui-virtual-index-list>
<!-- 多选确认按钮 -->
<!-- 操作 -->
<view class="opts" v-if="model.params.multiple">
<!-- 操作按钮 -->
<view class="opts-wrap">
<fui-button
v-for="opt in model.buttons"
:key="opt.value"
@tap="opt.onClick"
:text="opt.name"
:type="opt.type"
radius="96rpx"
:width="`${buttonWidth}rpx`"
height="96rpx"
/>
</view>
<!-- 安全区 -->
<fui-safe-area />
</view>
</view>
</template>
<style lang="less" scoped>
//
.multiple {
padding-bottom: 140rpx;
}
.opts {
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 100;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 20rpx 30rpx;
background-color: #fff;
box-shadow: 0 -2rpx 10rpx 0 rgb(0 0 0 / 10%);
.opts-wrap {
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
}
</style>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论