优化算法逻辑,提升性能

This commit is contained in:
weipengfei 2023-08-08 11:31:49 +08:00
parent a93d662ce5
commit 8e88c21e94
6 changed files with 91 additions and 65 deletions

View File

@ -17,7 +17,7 @@
</view> </view>
<view class="bottom"> <view class="bottom">
<view class="left"> <view class="left">
<uni-icons type="location"></uni-icons> <uni-icons type="location" color="#666666" size="13"></uni-icons>
<view class="location">区域:</view> <view class="location">区域:</view>
</view> </view>
<view style="flex: 1;">{{company.address}}</view> <view style="flex: 1;">{{company.address}}</view>
@ -317,16 +317,18 @@
.bottom { .bottom {
display: flex; display: flex;
align-items: flex-start; align-items: center;
color: #666666FF; color: #666666FF;
margin-top: 32rpx; margin-top: 32rpx;
.left { .left {
display: flex; display: flex;
align-items: center; align-items: center;
flex-shrink: 0;
.location { .location {
margin-left: 8rpx; margin-left: 5rpx;
margin-right: 5rpx;
} }
} }

13
static/server/archives.js Normal file
View File

@ -0,0 +1,13 @@
export const comonentList = [{
id: 7,
name: 'plant'
},
{
id: 8,
name: 'store'
},
{
id: 32,
name: 'breeding'
}
]

View File

@ -78,33 +78,9 @@
<view class="update_time"> <view class="update_time">
更新时间:{{item.update_time}} 更新时间:{{item.update_time}}
</view> </view>
<block> <component :is="listMap.get(item.id)" :datas="item.datas" :readonly="true"></component>
<breeding v-if="item.id==32" :datas="item.datas" :readonly="true" ref="demandRef32"></breeding>
<plant v-if="item.id==7" :datas="item.datas" :readonly="true" ref="demandRef7"></plant>
<store v-if="item.id==8" :datas="item.datas" :readonly="true" ref="demandRef8"></store>
<deepProcessing v-if="item.id==9" :datas="item.datas" :readonly="true" ref="demandRef9"></deepProcessing>
<thickProcessing v-if="item.id==10" :datas="item.datas" :readonly="true" ref="demandRef10">
</thickProcessing>
</block>
<block>
<houseRepair v-if="item.id==12" :datas="item.datas" :readonly="true" ref="demandRef12"></houseRepair>
<houseDecoration v-if="item.id==13" :datas="item.datas" :readonly="true" ref="demandRef13">
</houseDecoration>
<houseRenovate v-if="item.id==14" :datas="item.datas" :readonly="true" ref="demandRef14"></houseRenovate>
<houseTransaction v-if="item.id==15" :datas="item.datas" :readonly="true" ref="demandRef15">
</houseTransaction>
</block>
<block>
<banquetMarry v-if="item.id==17" :datas="item.datas" :readonly="true" ref="demandRef17"></banquetMarry>
<banquetBirthday v-if="item.id==18" :datas="item.datas" :readonly="true" ref="demandRef18">
</banquetBirthday>
<banquetFullMoon v-if="item.id==19" :datas="item.datas" :readonly="true" ref="demandRef19">
</banquetFullMoon>
<banquetOther v-if="item.id==20" :datas="item.datas" :readonly="true" ref="demandRef20"></banquetOther>
<banquetFuneral v-if="item.id==21" :datas="item.datas" :readonly="true" ref="demandRef21"></banquetFuneral>
</block>
</block> </block>
<u-empty v-if="formData.datas.length==0" icon="/static/img/empty/data.png" text="没有数据"></u-empty> <u-empty v-if="formData.datas.length==0" icon="/static/img/empty/data.png" text="没有数据"></u-empty>
</view> </view>
</u-skeleton> </u-skeleton>
</view> </view>
@ -113,6 +89,7 @@
<script> <script>
import { Toast } from "../../libs/uniApi" import { Toast } from "../../libs/uniApi"
import { informationAdd, informationDetails } from "@/api/information.js" import { informationAdd, informationDetails } from "@/api/information.js"
import { comonentList } from '@/static/server/archives.js'
import districtSelector from "@/components/districtSelector/districtSelector.vue" // import districtSelector from "@/components/districtSelector/districtSelector.vue" //
import residents from "@/components/newArchives/residents.vue" // import residents from "@/components/newArchives/residents.vue" //
import breeding from "@/components/newArchives/breeding.vue" // import breeding from "@/components/newArchives/breeding.vue" //
@ -150,6 +127,7 @@
}, },
data() { data() {
return { return {
listMap: new Map(),
tabLists: [{ tabLists: [{
name: '基本信息', name: '基本信息',
}, { }, {
@ -172,29 +150,36 @@
category_id: 1, category_id: 1,
category_child: 1, category_child: 1,
data_type: '1', data_type: '1',
datas: [] datas: []
}, },
} }
}, },
onLoad(options) { onLoad(options) {
this.initInformationDetails({ id: options.id }) this.initInformationDetails({ id: options.id });
this.initMap();
}, },
onShow() {}, onShow() {},
computed:{ computed: {
nowAddress(){ nowAddress() {
let address = this.$store.state.app.userInfo; let address = this.$store.state.app.userInfo;
return address.province_name+address.city_name+address.area_name+address.street_name+address.village_name+address.brigade_name; return address.province_name + address.city_name + address.area_name + address.street_name + address
} .village_name + address.brigade_name;
}
}, },
methods: { methods: {
initMap() {
comonentList.forEach(item => {
this.listMap.set(item.id, item.name);
})
},
async initInformationDetails(id) { async initInformationDetails(id) {
let res = await informationDetails(id); let res = await informationDetails(id);
uni.$u.sleep(500).then(() => { this.$u.sleep(500).then(()=>{
this.skeleton = false; this.skeleton = false;
Object.keys(res.data).forEach(key=>{ Object.keys(res.data).forEach(key => {
this.formData[key]=res.data[key]; this.formData[key] = res.data[key];
}) })
}) })
}, },
toastShow() { toastShow() {
@ -233,8 +218,8 @@
color: #fff; color: #fff;
} }
} }
.update_time{ .update_time {
padding-left: 28rpx; padding-left: 28rpx;
padding-top: 28rpx; padding-top: 28rpx;
} }

View File

@ -187,6 +187,7 @@
.card { .card {
width: 694rpx; width: 694rpx;
min-height: 180rpx;
background: #FFFFFF; background: #FFFFFF;
margin-top: 38.55rpx; margin-top: 38.55rpx;
box-shadow: 0rpx 0rpx 18rpx 2rpx rgba(50, 116, 249, 0.1); box-shadow: 0rpx 0rpx 18rpx 2rpx rgba(50, 116, 249, 0.1);
@ -195,7 +196,7 @@
padding: 31.5rpx 28rpx; padding: 31.5rpx 28rpx;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-around;
position: absolute; position: absolute;
top: 0; top: 0;
@ -208,7 +209,7 @@
.item { .item {
display: flex; display: flex;
justify-content: space-between; justify-content: space-around;
font-size: 32rpx; font-size: 32rpx;
font-weight: 400; font-weight: 400;
color: #333333; color: #333333;

View File

@ -2,7 +2,7 @@
<view class=""> <view class="">
<view class="card"> <view class="card">
<u--form labelPosition="left" :model="formData" ref="archives"> <u--form labelPosition="left" :model="formData" ref="archives">
<!-- <view class="item" style="margin-top: 30rpx;"> <!-- <view class="item" style="margin-top: 30rpx;">
<view class="title">基本信息</view> <view class="title">基本信息</view>
<u-form-item labelWidth="auto" label="姓名" required prop="name" borderBottom> <u-form-item labelWidth="auto" label="姓名" required prop="name" borderBottom>
<u--input readonly v-model="formData.name" placeholder="请输入姓名"></u--input> <u--input readonly v-model="formData.name" placeholder="请输入姓名"></u--input>
@ -25,9 +25,10 @@
<u--input readonly v-model="formData.phone" placeholder="请输入手机号" type="number"></u--input> <u--input readonly v-model="formData.phone" placeholder="请输入手机号" type="number"></u--input>
</u-form-item> </u-form-item>
</view> --> </view> -->
<u-empty v-if="showDemandList.length==0" text="暂无更新内容,点击下方按钮添加" icon="/static/img/empty/list.png"></u-empty> <u-empty v-if="showDemandList.length==0" text="暂无更新内容,点击下方按钮添加" icon="/static/img/empty/list.png"></u-empty>
<block v-for="(item, index) in showDemandList" :key="'demand'+index"> <component v-for="(item, index) in showDemandList" ref="componentRef" :key="'demand'+index" :is="listMap.get(item.id)"></component>
<!-- <block v-for="(item, index) in showDemandList" :key="'demand'+index">
<block> <block>
<breeding v-if="item.id==32" ref="demandRef32"></breeding> <breeding v-if="item.id==32" ref="demandRef32"></breeding>
<plant v-if="item.id==7" ref="demandRef7"></plant> <plant v-if="item.id==7" ref="demandRef7"></plant>
@ -49,7 +50,7 @@
<banquetFuneral v-if="item.id==21" ref="demandRef21"></banquetFuneral> <banquetFuneral v-if="item.id==21" ref="demandRef21"></banquetFuneral>
</block> </block>
<button class="delete" @click="removeShowDemand(index)">删除以上信息</button> <button class="delete" @click="removeShowDemand(index)">删除以上信息</button>
</block> </block> -->
<button class="plus demand" style="margin-bottom: 150rpx;" @click="demandShow=true">点击添加更多需求</button> <button class="plus demand" style="margin-bottom: 150rpx;" @click="demandShow=true">点击添加更多需求</button>
<u-picker :show="demandShow" ref="demandRef" :loading="demandLoading" :columns="[demandList, demandListChild]" <u-picker :show="demandShow" ref="demandRef" :loading="demandLoading" :columns="[demandList, demandListChild]"
keyName="name" @change="changeHandler" @cancel="demandShow = false" @confirm="changeDemand"></u-picker> keyName="name" @change="changeHandler" @cancel="demandShow = false" @confirm="changeDemand"></u-picker>
@ -61,6 +62,7 @@
</template> </template>
<script> <script>
import { comonentList } from '@/static/server/archives.js'
import { Toast } from "../../libs/uniApi" import { Toast } from "../../libs/uniApi"
import { informationDetails, informationOpportunityUpdate } from "@/api/information.js" import { informationDetails, informationOpportunityUpdate } from "@/api/information.js"
import { debounce, throttle } from "lodash" import { debounce, throttle } from "lodash"
@ -102,6 +104,7 @@
}, },
data() { data() {
return { return {
listMap: new Map(),
demandShow: false, demandShow: false,
demandLoading: false, demandLoading: false,
demandList: [], // demandList: [], //
@ -127,16 +130,22 @@
onLoad(options) { onLoad(options) {
this.initInformationDetails({ id: options.id }) this.initInformationDetails({ id: options.id })
this.initCategoryBusinessList(); this.initCategoryBusinessList();
this.initMap();
}, },
onShow() {}, onShow() {},
methods: { methods: {
initMap() {
comonentList.forEach(item => {
this.listMap.set(item.id, item.name);
})
},
async initInformationDetails(id) { async initInformationDetails(id) {
let res = await informationDetails(id); let res = await informationDetails(id);
this.formData = res.data; this.formData = res.data;
}, },
// //
addArchives: throttle(async function() { addArchives: throttle(async function() {
if(this.showDemandList.length==0)return Toast('请先添加需求!'); if (this.showDemandList.length == 0) return Toast('请先添加需求!');
let refsDatas = await this.loadRefsDatas(); let refsDatas = await this.loadRefsDatas();
if (!this.updateFlag) return; if (!this.updateFlag) return;
uni.showLoading({ uni.showLoading({
@ -162,23 +171,38 @@
async loadRefsDatas() { async loadRefsDatas() {
this.updateFlag = true; this.updateFlag = true;
let datas = []; let datas = [];
let map = new Map(); // 使mapref let i = 0;
for (let demand of this.showDemandList) { for(let c of this.$refs.componentRef){
if (map.get(demand.id) >= 0) map.set(demand.id, map.get(demand.id) + 1);
else map.set(demand.id, 0);
let now = map.get(demand.id);
try { try {
let res = await this.$refs['demandRef' + demand.id][now].validate(); let res = await c.validate();
if (!!res) datas.push({ if (!!res) datas.push({
card_id: demand.id, card_id: this.showDemandList[i].id,
datas: { ...this.$refs['demandRef' + demand.id][now]['formData'] } datas: { ...c.formData }
}) })
} catch (e) { i++;
console.log('err', e); } catch (e) {
this.updateFlag = false; console.log('err', e);
Toast('请完整填写以上数据!') this.updateFlag = false;
} Toast('请完整填写以上数据!')
}
} }
// let map = new Map(); // 使mapref
// for (let demand of this.showDemandList) {
// if (map.get(demand.id) >= 0) map.set(demand.id, map.get(demand.id) + 1);
// else map.set(demand.id, 0);
// let now = map.get(demand.id);
// try {
// let res = await this.$refs['demandRef' + demand.id][now].validate();
// if (!!res) datas.push({
// card_id: demand.id,
// datas: { ...this.$refs['demandRef' + demand.id][now]['formData'] }
// })
// } catch (e) {
// console.log('err', e);
// this.updateFlag = false;
// Toast('!')
// }
// }
return datas; return datas;
}, },
// //

View File

@ -158,7 +158,7 @@
padding: 31.5rpx 28rpx; padding: 31.5rpx 28rpx;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-around;
position: absolute; position: absolute;
top: 0; top: 0;
@ -187,6 +187,7 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding: 0 28rpx; padding: 0 28rpx;
margin-top: 50rpx;
.title { .title {
font-size: 32rpx; font-size: 32rpx;