优化算法逻辑,提升性能

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 class="bottom">
<view class="left">
<uni-icons type="location"></uni-icons>
<uni-icons type="location" color="#666666" size="13"></uni-icons>
<view class="location">区域:</view>
</view>
<view style="flex: 1;">{{company.address}}</view>
@ -317,16 +317,18 @@
.bottom {
display: flex;
align-items: flex-start;
align-items: center;
color: #666666FF;
margin-top: 32rpx;
.left {
display: flex;
align-items: center;
flex-shrink: 0;
.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">
更新时间:{{item.update_time}}
</view>
<block>
<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>
<component :is="listMap.get(item.id)" :datas="item.datas" :readonly="true"></component>
</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>
</u-skeleton>
</view>
@ -113,6 +89,7 @@
<script>
import { Toast } from "../../libs/uniApi"
import { informationAdd, informationDetails } from "@/api/information.js"
import { comonentList } from '@/static/server/archives.js'
import districtSelector from "@/components/districtSelector/districtSelector.vue" //
import residents from "@/components/newArchives/residents.vue" //
import breeding from "@/components/newArchives/breeding.vue" //
@ -150,6 +127,7 @@
},
data() {
return {
listMap: new Map(),
tabLists: [{
name: '基本信息',
}, {
@ -172,29 +150,36 @@
category_id: 1,
category_child: 1,
data_type: '1',
datas: []
datas: []
},
}
},
onLoad(options) {
this.initInformationDetails({ id: options.id })
this.initInformationDetails({ id: options.id });
this.initMap();
},
onShow() {},
computed:{
nowAddress(){
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;
}
computed: {
nowAddress() {
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;
}
},
methods: {
initMap() {
comonentList.forEach(item => {
this.listMap.set(item.id, item.name);
})
},
async initInformationDetails(id) {
let res = await informationDetails(id);
uni.$u.sleep(500).then(() => {
this.$u.sleep(500).then(()=>{
this.skeleton = false;
Object.keys(res.data).forEach(key=>{
this.formData[key]=res.data[key];
})
Object.keys(res.data).forEach(key => {
this.formData[key] = res.data[key];
})
})
},
toastShow() {
@ -233,8 +218,8 @@
color: #fff;
}
}
.update_time{
.update_time {
padding-left: 28rpx;
padding-top: 28rpx;
}

View File

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

View File

@ -2,7 +2,7 @@
<view class="">
<view class="card">
<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>
<u-form-item labelWidth="auto" label="姓名" required prop="name" borderBottom>
<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-form-item>
</view> -->
<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>
<breeding v-if="item.id==32" ref="demandRef32"></breeding>
<plant v-if="item.id==7" ref="demandRef7"></plant>
@ -49,7 +50,7 @@
<banquetFuneral v-if="item.id==21" ref="demandRef21"></banquetFuneral>
</block>
<button class="delete" @click="removeShowDemand(index)">删除以上信息</button>
</block>
</block> -->
<button class="plus demand" style="margin-bottom: 150rpx;" @click="demandShow=true">点击添加更多需求</button>
<u-picker :show="demandShow" ref="demandRef" :loading="demandLoading" :columns="[demandList, demandListChild]"
keyName="name" @change="changeHandler" @cancel="demandShow = false" @confirm="changeDemand"></u-picker>
@ -61,6 +62,7 @@
</template>
<script>
import { comonentList } from '@/static/server/archives.js'
import { Toast } from "../../libs/uniApi"
import { informationDetails, informationOpportunityUpdate } from "@/api/information.js"
import { debounce, throttle } from "lodash"
@ -102,6 +104,7 @@
},
data() {
return {
listMap: new Map(),
demandShow: false,
demandLoading: false,
demandList: [], //
@ -127,16 +130,22 @@
onLoad(options) {
this.initInformationDetails({ id: options.id })
this.initCategoryBusinessList();
this.initMap();
},
onShow() {},
methods: {
initMap() {
comonentList.forEach(item => {
this.listMap.set(item.id, item.name);
})
},
async initInformationDetails(id) {
let res = await informationDetails(id);
this.formData = res.data;
},
//
addArchives: throttle(async function() {
if(this.showDemandList.length==0)return Toast('请先添加需求!');
if (this.showDemandList.length == 0) return Toast('请先添加需求!');
let refsDatas = await this.loadRefsDatas();
if (!this.updateFlag) return;
uni.showLoading({
@ -162,23 +171,38 @@
async loadRefsDatas() {
this.updateFlag = true;
let datas = [];
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);
let i = 0;
for(let c of this.$refs.componentRef){
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('请完整填写以上数据!')
}
let res = await c.validate();
if (!!res) datas.push({
card_id: this.showDemandList[i].id,
datas: { ...c.formData }
})
i++;
} catch (e) {
console.log('err', e);
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;
},
//

View File

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