新建工成

This commit is contained in:
仲么了
2023-04-12 18:39:52 +08:00
parent d6b2c98d1f
commit ff2fd537ec
11 changed files with 1105 additions and 1071 deletions

36
common/api/gc.js Normal file
View File

@@ -0,0 +1,36 @@
import request from '../js/request';
import config from '../js/config';
export function addEngineering(params, files) {
return request({
url: '/engineering/addEngineering',
method: 'post',
data: params,
header: {
'Content-Type': 'application/json',
},
});
}
export function auditEngineering(params) {
return request({
url: '/engineering/auditEngineering',
method: 'post',
data: params,
header: {
'Content-Type': 'application/json',
},
});
}
export function queryEngineering(params) {
return request({
url: '/engineering/queryEngineering',
method: 'post',
data: params,
header: {
'Content-Type': 'application/json',
},
});
}

View File

@@ -49,7 +49,7 @@ export default {
}).then((res) => { }).then((res) => {
console.warn(res); console.warn(res);
let resultData = let resultData =
res.data?.list || res.data?.records || []; res.data?.list || res.data?.records || [];
if (this.params.currentPage == 1) { if (this.params.currentPage == 1) {
this.data = resultData; this.data = resultData;
if (resultData.length == 0 || resultData == 0) { if (resultData.length == 0 || resultData == 0) {

View File

@@ -8,12 +8,12 @@
v-for="(item, index) in store.data" :key="index"> v-for="(item, index) in store.data" :key="index">
<view class="term-list-bottom"> <view class="term-list-bottom">
<view class="term-list-bottom-item"> <view class="term-list-bottom-item">
<view>设备个数</view> <view>区域</view>
<view>3</view> <view>{{ item.province +item.city}}</view>
</view> </view>
<view class="term-list-bottom-item"> <view class="term-list-bottom-item">
<view>用户个数</view> <view>创建时间</view>
<view>1</view> <view>{{ item.createTime}}</view>
</view> </view>
</view> </view>
</uni-card> </uni-card>
@@ -35,7 +35,7 @@ export default {
}, },
methods: { methods: {
init () { init () {
this.store = this.DataSource('/engineering/queryEngineering') this.store = this.DataSource('/engineering/queryEngineeringPage')
this.store.params.userId = uni.getStorageSync('userInfo').id this.store.params.userId = uni.getStorageSync('userInfo').id
this.store.reload() this.store.reload()
}, },

View File

@@ -5,15 +5,16 @@
<view class="content"> <view class="content">
<uni-forms :label-width="80"> <uni-forms :label-width="80">
<uni-forms-item label="工程名称"> <uni-forms-item label="工程名称">
<uni-easyinput type="number" v-model="formData.name" placeholder="请输入工程名称" /> <uni-easyinput type="text" v-model="formData.name" placeholder="请输入工程名称" />
</uni-forms-item> </uni-forms-item>
<uni-forms-item label="位置"> <uni-forms-item label="位置">
<view style="display:flex;"> <!-- <view style="display:flex;">
<uni-easyinput :clearable="false" type="textarea" autoHeight v-model="formData.area" <uni-easyinput :clearable="false" type="textarea" autoHeight v-model="formData.area"
placeholder="请输入位置信息" /> placeholder="请输入位置信息" />
<uni-icons type="location" color="#007aff" size="26" class="ml20" <uni-icons type="location" color="#007aff" size="26" class="ml20"
@click="chooseLocation"></uni-icons> @click="chooseLocation"></uni-icons>
</view> </view> -->
<uni-data-picker :localdata="localdata" @change="areaChange"> </uni-data-picker>
</uni-forms-item> </uni-forms-item>
<uni-forms-item label="描述"> <uni-forms-item label="描述">
<uni-easyinput type="textarea" autoHeight v-model="formData.description" <uni-easyinput type="textarea" autoHeight v-model="formData.description"
@@ -29,35 +30,22 @@
</Cn-page> </Cn-page>
</template> </template>
<script> <script>
import { addAppProject } from '../../common/api/project' import { addEngineering } from '../../common/api/gc'
// import area from '../../common/js/area.json' import area from '../../common/js/area.json'
export default { export default {
data () { data() {
return { return {
localdata: area,
loading: false, loading: false,
formData: { formData: {
area: "", city: "",
files: [], description: "",
description: '', name: "",
projectType: '1', province: "",
name: '',
userId: '123456',
lat: '2',
lng: '3'
}, },
TypeRange: [
{
text: '监测',
value: '1'
},
{
text: '用能',
value: '2'
}
]
} }
}, },
onLoad () { onLoad() {
uni.getLocation({ uni.getLocation({
type: 'wgs84', type: 'wgs84',
success: function (res) { success: function (res) {
@@ -69,10 +57,15 @@ export default {
// console.log(area); // console.log(area);
}, },
methods: { methods: {
select (e) { areaChange(e) {
console.log(e);
this.formData.province = e.detail.value[0].value
this.formData.city = e.detail.value[1].value
},
select(e) {
console.log(e); console.log(e);
}, },
chooseLocation () { chooseLocation() {
uni.chooseLocation({ uni.chooseLocation({
success: function (res) { success: function (res) {
@@ -84,43 +77,26 @@ export default {
} }
}); });
}, },
async submit () { async submit() {
if (!this.formData.name) { if (!this.formData.name) {
this.$util.toast('请输入工程名称') this.$util.toast('请输入工程名称')
return return
} }
if (!this.formData.projectType) {
this.$util.toast('请选择工程类别') if (!this.formData.province) {
return this.$util.toast('请选择区域信息')
}
if (!this.formData.area) {
this.$util.toast('请输入区域信息')
return return
} }
if (!this.formData.description) { if (!this.formData.description) {
this.$util.toast('请输入工程描述') this.$util.toast('请输入工程描述')
return return
} }
if (!this.formData.files.length) { addEngineering(this.formData).then(res => {
this.$util.toast('请上传拓扑图')
return
}
let arr = []
for (let i = 0; i < this.formData.files.length; i++) {
let item = this.formData.files[i]
arr.push({
name: 'files',
url: item.url
})
}
let data = JSON.parse(JSON.stringify(this.formData))
delete data.files
addAppProject(data, arr).then(res => {
console.log(res) console.log(res)
this.$util.toast('工程创建成功') this.$util.toast('工程创建成功')
// setTimeout(() => { setTimeout(() => {
// uni.navigateBack({ delta: 1 }) uni.navigateBack({ delta: 1 })
// }, 1500); }, 1500);
}) })
} }
} }

View File

@@ -47,6 +47,7 @@
</template> </template>
<script> <script>
import { pinyin } from 'pinyin-pro'; import { pinyin } from 'pinyin-pro';
import { queryEngineering } from '@/common/api/gc.js'
export default { export default {
data() { data() {
@@ -133,47 +134,7 @@ export default {
} }
], ],
gcList: [ gcList: [
'南京灿能',
'南京灿能',
'南京灿能',
'南京灿能',
'南京灿能',
'北京灿能',
'北京灿能',
'北京灿能',
'北京灿能',
'北京灿能',
'上海灿能',
'上海灿能',
'上海灿能',
'上海灿能',
'上海灿能',
'上海灿能',
'广州灿能',
'广州灿能',
'广州灿能',
'广州灿能',
'广州灿能',
'深圳灿能',
'深圳灿能',
'深圳灿能',
'深圳灿能',
'深圳灿能',
'杭州灿能',
'杭州灿能',
'杭州灿能',
'杭州灿能',
'杭州灿能',
'杭州灿能',
'杭州灿能',
'苏州灿能',
'苏州灿能',
'苏州灿能',
'苏州灿能',
'苏州灿能',
'苏州灿能',
'苏州灿能',
'苏州灿能',
] ]
} }
}, },
@@ -202,17 +163,17 @@ export default {
let result = [] let result = []
this.gcList.forEach(item => { this.gcList.forEach(item => {
let arr = pinyin(item[0], { toneType: 'none', type: 'array' }) let arr = pinyin(item.name[0], { toneType: 'none', type: 'array' })
let letter = arr[0][0].toUpperCase() let letter = arr[0][0].toUpperCase()
console.log(letter); console.log(letter);
let index = result.findIndex(item => item.letter === letter) let index = result.findIndex(item => item.letter === letter)
if (index === -1) { if (index === -1) {
result.push({ result.push({
letter, letter,
data: [item] data: [item.name]
}) })
} else { } else {
result[index].data.push(item) result[index].data.push(item.name)
} }
}) })
return result return result
@@ -234,7 +195,9 @@ export default {
showDrawer() { showDrawer() {
this.$refs.showRight.open(); this.$refs.showRight.open();
}, },
closeDrawer() { closeDrawer(e) {
console.log(e);
this.$refs.showRight.close(); this.$refs.showRight.close();
}, },
submitFeedBack() { uni.navigateTo({ url: '/pages/home/feedback' }) }, submitFeedBack() { uni.navigateTo({ url: '/pages/home/feedback' }) },
@@ -304,10 +267,16 @@ export default {
}) })
} }
}, },
init(){
queryEngineering().then(res => {
this.gcList = res.data
})
}
}, },
mounted() { mounted() {
this.userInfo = uni.getStorageSync('userInfo') this.userInfo = uni.getStorageSync('userInfo')
setTimeout(() => { setTimeout(() => {
this.init()
// 获取nav高度 // 获取nav高度
uni.createSelectorQuery().select('.nav').boundingClientRect((rect) => { uni.createSelectorQuery().select('.nav').boundingClientRect((rect) => {
this.navHeight = rect.height this.navHeight = rect.height

View File

@@ -33,7 +33,7 @@
<uni-icons type="forward" color="#aaa" size="20"></uni-icons> <uni-icons type="forward" color="#aaa" size="20"></uni-icons>
</view> </view>
<view class="mine-nav" @click="jump('gc')" <view class="mine-nav" @click="jump('gc')"
v-if="userInfo.role == 4 || userInfo.role == 3 || userInfo.role == 2"> v-if="userInfo.role == 4 || userInfo.role == 3 ">
<image mode="aspectFill" class="mine-nav-icon" src="/static/project.png" /> <image mode="aspectFill" class="mine-nav-icon" src="/static/project.png" />
<view class="mine-nav-label">工程管理</view> <view class="mine-nav-label">工程管理</view>
<uni-icons type="forward" color="#aaa" size="20"></uni-icons> <uni-icons type="forward" color="#aaa" size="20"></uni-icons>

View File

@@ -1,3 +1,12 @@
## 1.1.22023-04-11
- 修复 更改 modelValue 报错的 bug
- 修复 v-for 未使用 key 值控制台 warning
## 1.1.12023-02-21
- 修复代码合并时引发 value 属性为空时不渲染数据的问题
## 1.1.02023-02-15
- 修复 localdata 不支持动态更新的bug
## 1.0.92023-02-15
- 修复 localdata 不支持动态更新的bug
## 1.0.82022-09-16 ## 1.0.82022-09-16
- 可以使用 uni-scss 控制主题色 - 可以使用 uni-scss 控制主题色
## 1.0.72022-07-06 ## 1.0.72022-07-06

View File

@@ -42,7 +42,7 @@ export default {
}, },
pageSize: { pageSize: {
type: Number, type: Number,
default: 20 default: 500
}, },
getcount: { getcount: {
type: [Boolean, String], type: [Boolean, String],
@@ -94,7 +94,7 @@ export default {
}, },
map: { map: {
type: Object, type: Object,
default() { default () {
return { return {
text: "text", text: "text",
value: "value" value: "value"
@@ -122,19 +122,22 @@ export default {
} }
}, },
computed: { computed: {
isLocaldata() { isLocalData() {
return !this.collection.length return !this.collection.length;
}, },
postField() { isCloudData() {
let fields = [this.field]; return this.collection.length > 0;
if (this.parentField) { },
fields.push(`${this.parentField} as parent_value`); isCloudDataList() {
} return (this.isCloudData && (!this.parentField && !this.selfField));
return fields.join(','); },
isCloudDataTree() {
return (this.isCloudData && this.parentField && this.selfField);
}, },
dataValue() { dataValue() {
let isModelValue = Array.isArray(this.modelValue) ? (this.modelValue.length > 0) : (this.modelValue !== null || this.modelValue !== undefined) let isModelValue = Array.isArray(this.modelValue) ? (this.modelValue.length > 0) : (this.modelValue !== null ||
return isModelValue ? this.modelValue : this.value this.modelValue !== undefined);
return isModelValue ? this.modelValue : this.value;
}, },
hasValue() { hasValue() {
if (typeof this.dataValue === 'number') { if (typeof this.dataValue === 'number') {
@@ -183,8 +186,169 @@ export default {
}, },
methods: { methods: {
onPropsChange() { onPropsChange() {
this._treeData = [] this._treeData = [];
}, },
// 填充 pickview 数据
async loadData() {
if (this.isLocalData) {
this.loadLocalData();
} else if (this.isCloudDataList) {
this.loadCloudDataList();
} else if (this.isCloudDataTree) {
this.loadCloudDataTree();
}
},
// 加载本地数据
async loadLocalData() {
this._treeData = [];
this._extractTree(this.localdata, this._treeData);
let inputValue = this.dataValue;
if (inputValue === undefined) {
return;
}
if (Array.isArray(inputValue)) {
inputValue = inputValue[inputValue.length - 1];
if (typeof inputValue === 'object' && inputValue[this.map.value]) {
inputValue = inputValue[this.map.value];
}
}
this.selected = this._findNodePath(inputValue, this.localdata);
},
// 加载 Cloud 数据 (单列)
async loadCloudDataList() {
if (this.loading) {
return;
}
this.loading = true;
try {
let response = await this.getCommand();
let responseData = response.result.data;
this._treeData = responseData;
this._updateBindData();
this._updateSelected();
this.onDataChange();
} catch (e) {
this.errorMessage = e;
} finally {
this.loading = false;
}
},
// 加载 Cloud 数据 (树形)
async loadCloudDataTree() {
if (this.loading) {
return;
}
this.loading = true;
try {
let commandOptions = {
field: this._cloudDataPostField(),
where: this._cloudDataTreeWhere()
};
if (this.gettree) {
commandOptions.startwith = `${this.selfField}=='${this.dataValue}'`;
}
let response = await this.getCommand(commandOptions);
let responseData = response.result.data;
this._treeData = responseData;
this._updateBindData();
this._updateSelected();
this.onDataChange();
} catch (e) {
this.errorMessage = e;
} finally {
this.loading = false;
}
},
// 加载 Cloud 数据 (节点)
async loadCloudDataNode(callback) {
if (this.loading) {
return;
}
this.loading = true;
try {
let commandOptions = {
field: this._cloudDataPostField(),
where: this._cloudDataNodeWhere()
};
let response = await this.getCommand(commandOptions);
let responseData = response.result.data;
callback(responseData);
} catch (e) {
this.errorMessage = e;
} finally {
this.loading = false;
}
},
// 回显 Cloud 数据
getCloudDataValue() {
if (this.isCloudDataList) {
return this.getCloudDataListValue();
}
if (this.isCloudDataTree) {
return this.getCloudDataTreeValue();
}
},
// 回显 Cloud 数据 (单列)
getCloudDataListValue() {
// 根据 field's as value标识匹配 where 条件
let where = [];
let whereField = this._getForeignKeyByField();
if (whereField) {
where.push(`${whereField} == '${this.dataValue}'`)
}
where = where.join(' || ');
if (this.where) {
where = `(${this.where}) && (${where})`
}
return this.getCommand({
field: this._cloudDataPostField(),
where
}).then((res) => {
this.selected = res.result.data;
return res.result.data;
});
},
// 回显 Cloud 数据 (树形)
getCloudDataTreeValue() {
return this.getCommand({
field: this._cloudDataPostField(),
getTreePath: {
startWith: `${this.selfField}=='${this.dataValue}'`
}
}).then((res) => {
let treePath = [];
this._extractTreePath(res.result.data, treePath);
this.selected = treePath;
return treePath;
});
},
getCommand(options = {}) { getCommand(options = {}) {
/* eslint-disable no-undef */ /* eslint-disable no-undef */
let db = uniCloud.database(this.spaceInfo) let db = uniCloud.database(this.spaceInfo)
@@ -229,125 +393,16 @@ export default {
return db return db
}, },
getNodeData(callback) {
if (this.loading) {
return
}
this.loading = true
this.getCommand({
field: this.postField,
where: this._pathWhere()
}).then((res) => {
this.loading = false
this.selected = res.result.data
callback && callback()
}).catch((err) => {
this.loading = false
this.errorMessage = err
})
},
getTreePath(callback) {
if (this.loading) {
return
}
this.loading = true
this.getCommand({ _cloudDataPostField() {
field: this.postField, let fields = [this.field];
getTreePath: { if (this.parentField) {
startWith: `${this.selfField}=='${this.dataValue}'` fields.push(`${this.parentField} as parent_value`);
} }
}).then((res) => { return fields.join(',');
this.loading = false
let treePath = []
this._extractTreePath(res.result.data, treePath)
this.selected = treePath
callback && callback()
}).catch((err) => {
this.loading = false
this.errorMessage = err
})
}, },
loadData() {
if (this.isLocaldata) {
this._processLocalData()
return
}
if (this.dataValue != null) { _cloudDataTreeWhere() {
this._loadNodeData((data) => {
this._treeData = data
this._updateBindData()
this._updateSelected()
})
return
}
if (this.stepSearh) {
this._loadNodeData((data) => {
this._treeData = data
this._updateBindData()
})
} else {
this._loadAllData((data) => {
this._treeData = []
this._extractTree(data, this._treeData, null)
this._updateBindData()
})
}
},
_loadAllData(callback) {
if (this.loading) {
return
}
this.loading = true
this.getCommand({
field: this.postField,
gettree: true,
startwith: `${this.selfField}=='${this.dataValue}'`
}).then((res) => {
this.loading = false
callback(res.result.data)
this.onDataChange()
}).catch((err) => {
this.loading = false
this.errorMessage = err
})
},
_loadNodeData(callback, pw) {
if (this.loading) {
return
}
this.loading = true
this.getCommand({
field: this.postField,
where: pw || this._postWhere(),
pageSize: 500
}).then((res) => {
this.loading = false
callback(res.result.data)
this.onDataChange()
}).catch((err) => {
this.loading = false
this.errorMessage = err
})
},
_pathWhere() {
let result = []
let where_field = this._getParentNameByField();
if (where_field) {
result.push(`${where_field} == '${this.dataValue}'`)
}
if (this.where) {
return `(${this.where}) && (${result.join(' || ')})`
}
return result.join(' || ')
},
_postWhere() {
let result = [] let result = []
let selected = this.selected let selected = this.selected
let parentField = this.parentField let parentField = this.parentField
@@ -364,17 +419,35 @@ export default {
if (this.where) { if (this.where) {
where.push(`(${this.where})`) where.push(`(${this.where})`)
} }
if (result.length) { if (result.length) {
where.push(`(${result.join(' || ')})`) where.push(`(${result.join(' || ')})`)
} }
return where.join(' && ') return where.join(' && ')
}, },
_nodeWhere() {
let result = [] _cloudDataNodeWhere() {
let selected = this.selected let where = []
let selected = this.selected;
if (selected.length) { if (selected.length) {
result.push(`${this.parentField} == '${selected[selected.length - 1].value}'`) where.push(`${this.parentField} == '${selected[selected.length - 1].value}'`);
}
where = where.join(' || ');
if (this.where) {
return `(${this.where}) && (${where})`
}
return where
},
_getWhereByForeignKey() {
let result = []
let whereField = this._getForeignKeyByField();
if (whereField) {
result.push(`${whereField} == '${this.dataValue}'`)
} }
if (this.where) { if (this.where) {
@@ -383,41 +456,23 @@ export default {
return result.join(' || ') return result.join(' || ')
}, },
_getParentNameByField() {
const fields = this.field.split(','); _getForeignKeyByField() {
let where_field = null; let fields = this.field.split(',');
let whereField = null;
for (let i = 0; i < fields.length; i++) { for (let i = 0; i < fields.length; i++) {
const items = fields[i].split('as'); const items = fields[i].split('as');
if (items.length < 2) { if (items.length < 2) {
continue; continue;
} }
if (items[1].trim() === 'value') { if (items[1].trim() === 'value') {
where_field = items[0].trim(); whereField = items[0].trim();
break; break;
} }
} }
return where_field return whereField;
},
_isTreeView() {
return (this.parentField && this.selfField)
},
_updateSelected() {
var dl = this.dataList
var sl = this.selected
let textField = this.map.text
let valueField = this.map.value
for (var i = 0; i < sl.length; i++) {
var value = sl[i].value
var dl2 = dl[i]
for (var j = 0; j < dl2.length; j++) {
var item2 = dl2[j]
if (item2[valueField] === value) {
sl[i].text = item2[textField]
break
}
}
}
}, },
_updateBindData(node) { _updateBindData(node) {
const { const {
dataList, dataList,
@@ -445,6 +500,25 @@ export default {
hasNodes hasNodes
} }
}, },
_updateSelected() {
let dl = this.dataList
let sl = this.selected
let textField = this.map.text
let valueField = this.map.value
for (let i = 0; i < sl.length; i++) {
let value = sl[i].value
let dl2 = dl[i]
for (let j = 0; j < dl2.length; j++) {
let item2 = dl2[j]
if (item2[valueField] === value) {
sl[i].text = item2[textField]
break
}
}
}
},
_filterData(data, paths) { _filterData(data, paths) {
let dataList = [] let dataList = []
let hasNodes = true let hasNodes = true
@@ -453,8 +527,8 @@ export default {
return (item.parent_value === null || item.parent_value === undefined || item.parent_value === '') return (item.parent_value === null || item.parent_value === undefined || item.parent_value === '')
})) }))
for (let i = 0; i < paths.length; i++) { for (let i = 0; i < paths.length; i++) {
var value = paths[i].value let value = paths[i].value
var nodes = data.filter((item) => { let nodes = data.filter((item) => {
return item.parent_value === value return item.parent_value === value
}) })
@@ -470,6 +544,7 @@ export default {
hasNodes hasNodes
} }
}, },
_extractTree(nodes, result, parent_value) { _extractTree(nodes, result, parent_value) {
let list = result || [] let list = result || []
let valueField = this.map.value let valueField = this.map.value
@@ -493,6 +568,7 @@ export default {
} }
} }
}, },
_extractTreePath(nodes, result) { _extractTreePath(nodes, result) {
let list = result || [] let list = result || []
for (let i = 0; i < nodes.length; i++) { for (let i = 0; i < nodes.length; i++) {
@@ -512,6 +588,7 @@ export default {
} }
} }
}, },
_findNodePath(key, nodes, path = []) { _findNodePath(key, nodes, path = []) {
let textField = this.map.text let textField = this.map.text
let valueField = this.map.value let valueField = this.map.value
@@ -540,24 +617,6 @@ export default {
path.pop() path.pop()
} }
return [] return []
},
_processLocalData() {
this._treeData = []
this._extractTree(this.localdata, this._treeData)
var inputValue = this.dataValue
if (inputValue === undefined) {
return
}
if (Array.isArray(inputValue)) {
inputValue = inputValue[inputValue.length - 1]
if (typeof inputValue === 'object' && inputValue[this.map.value]) {
inputValue = inputValue[this.map.value]
}
}
this.selected = this._findNodePath(inputValue, this.localdata)
} }
} }
} }

View File

@@ -1,182 +1,171 @@
<template> <template>
<view class="uni-data-pickerview"> <view class="uni-data-pickerview">
<scroll-view class="selected-area" scroll-x="true" scroll-y="false" :show-scrollbar="false"> <scroll-view v-if="!isCloudDataList" class="selected-area" scroll-x="true">
<view class="selected-list"> <view class="selected-list">
<template v-for="(item,index) in selected"> <view
<view class="selected-item" class="selected-item"
:class="{'selected-item-active':index==selectedIndex, 'selected-item-text-overflow': ellipsis}" v-for="(item,index) in selected"
v-if="item.text" @click="handleSelect(index)"> :key="index"
<text class="">{{item.text}}</text> :class="{
</view> 'selected-item-active':index == selectedIndex
</template> }"
</view> @click="handleSelect(index)"
</scroll-view> >
<view class="tab-c"> <text>{{item.text || ''}}</text>
<template v-for="(child, i) in dataList" > </view>
<scroll-view class="list" :key="i" v-if="i==selectedIndex" :scroll-y="true"> </view>
<view class="item" :class="{'is-disabled': !!item.disable}" v-for="(item, j) in child" </scroll-view>
@click="handleNodeClick(item, i, j)"> <view class="tab-c">
<text class="item-text item-text-overflow">{{item[map.text]}}</text> <scroll-view class="list" :scroll-y="true">
<view class="check" v-if="selected.length > i && item[map.value] == selected[i].value"></view> <view class="item" :class="{'is-disabled': !!item.disable}" v-for="(item, j) in dataList[selectedIndex]" :key="j"
</view> @click="handleNodeClick(item, selectedIndex, j)">
</scroll-view> <text class="item-text">{{item[map.text]}}</text>
</template> <view class="check" v-if="selected.length > selectedIndex && item[map.value] == selected[selectedIndex].value"></view>
</view>
</scroll-view>
<view class="loading-cover" v-if="loading"> <view class="loading-cover" v-if="loading">
<uni-load-more class="load-more" :contentText="loadMore" status="loading"></uni-load-more> <uni-load-more class="load-more" :contentText="loadMore" status="loading"></uni-load-more>
</view> </view>
<view class="error-message" v-if="errorMessage"> <view class="error-message" v-if="errorMessage">
<text class="error-text">{{errorMessage}}</text> <text class="error-text">{{errorMessage}}</text>
</view> </view>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import dataPicker from "./uni-data-picker.js" import dataPicker from "./uni-data-picker.js"
/** /**
* DataPickerview * DataPickerview
* @description uni-data-pickerview * @description uni-data-pickerview
* @tutorial https://ext.dcloud.net.cn/plugin?id=3796 * @tutorial https://ext.dcloud.net.cn/plugin?id=3796
* @property {Array} localdata 本地数据,参考 * @property {Array} localdata 本地数据,参考
* @property {Boolean} step-searh = [true|false] 是否分布查询 * @property {Boolean} step-searh = [true|false] 是否分布查询
* @value true 启用分布查询,仅查询当前选中节点 * @value true 启用分布查询,仅查询当前选中节点
* @value false 关闭分布查询,一次查询出所有数据 * @value false 关闭分布查询,一次查询出所有数据
* @property {String|DBFieldString} self-field 分布查询当前字段名称 * @property {String|DBFieldString} self-field 分布查询当前字段名称
* @property {String|DBFieldString} parent-field 分布查询父字段名称 * @property {String|DBFieldString} parent-field 分布查询父字段名称
* @property {String|DBCollectionString} collection 表名 * @property {String|DBCollectionString} collection 表名
* @property {String|DBFieldString} field 查询字段,多个字段用 `,` 分割 * @property {String|DBFieldString} field 查询字段,多个字段用 `,` 分割
* @property {String} orderby 排序字段及正序倒叙设置 * @property {String} orderby 排序字段及正序倒叙设置
* @property {String|JQLString} where 查询条件 * @property {String|JQLString} where 查询条件
*/ */
export default { export default {
name: 'UniDataPickerView', name: 'UniDataPickerView',
emits: ['nodeclick', 'change', 'datachange', 'update:modelValue'], emits: ['nodeclick', 'change', 'datachange', 'update:modelValue'],
mixins: [dataPicker], mixins: [dataPicker],
props: { props: {
managedMode: { managedMode: {
type: Boolean, type: Boolean,
default: false default: false
}, },
ellipsis: { ellipsis: {
type: Boolean, type: Boolean,
default: true default: true
} }
}, },
data() { created() {
return {} if (!this.managedMode) {
}, this.$nextTick(() => {
created() { this.loadData();
if (this.managedMode) { })
return }
} },
methods: {
onPropsChange() {
this._treeData = [];
this.selectedIndex = 0;
this.$nextTick(() => {
this.loadData();
})
},
handleSelect(index) {
this.selectedIndex = index;
},
handleNodeClick(item, i, j) {
if (item.disable) {
return;
}
this.$nextTick(() => { const node = this.dataList[i][j];
this.load() const text = node[this.map.text];
}) const value = node[this.map.value];
},
methods: {
onPropsChange() {
this._treeData = []
this.selectedIndex = 0
this.load()
},
load() {
if (this.isLocaldata) {
this.loadData()
} else if (this.dataValue.length) {
this.getTreePath((res) => {
this.loadData()
})
}
},
handleSelect(index) {
this.selectedIndex = index
},
handleNodeClick(item, i, j) {
if (item.disable) {
return
}
const node = this.dataList[i][j]
const text = node[this.map.text]
const value = node[this.map.value]
if (i < this.selected.length - 1) {
this.selected.splice(i, this.selected.length - i)
this.selected.push({
text,
value
})
} else if (i === this.selected.length - 1) {
this.selected.splice(i, 1, {
text,
value
})
}
if (node.isleaf) { if (i < this.selected.length - 1) {
this.onSelectedChange(node, node.isleaf) this.selected.splice(i, this.selected.length - i)
return this.selected.push({
} text,
value
})
} else if (i === this.selected.length - 1) {
this.selected.splice(i, 1, {
text,
value
})
}
const { if (node.isleaf) {
isleaf, this.onSelectedChange(node, node.isleaf)
hasNodes return
} = this._updateBindData() }
if (!this._isTreeView() && !hasNodes) { const {
this.onSelectedChange(node, true) isleaf,
return hasNodes
} } = this._updateBindData()
if (this.isLocaldata && (!hasNodes || isleaf)) { // 本地数据
this.onSelectedChange(node, true) if (this.isLocalData) {
return this.onSelectedChange(node, (!hasNodes || isleaf))
} } else if (this.isCloudDataList) { // Cloud 数据 (单列)
this.onSelectedChange(node, true)
} else if (this.isCloudDataTree) { // Cloud 数据 (树形)
if (isleaf) {
this.onSelectedChange(node, node.isleaf)
} else if (!hasNodes) { // 请求一次服务器以确定是否为叶子节点
this.loadCloudDataNode((data) => {
if (!data.length) {
node.isleaf = true
} else {
this._treeData.push(...data)
this._updateBindData(node)
}
this.onSelectedChange(node, node.isleaf)
})
}
}
},
updateData(data) {
this._treeData = data.treeData
this.selected = data.selected
if (!this._treeData.length) {
this.loadData()
} else {
//this.selected = data.selected
this._updateBindData()
}
},
onDataChange() {
this.$emit('datachange');
},
onSelectedChange(node, isleaf) {
if (isleaf) {
this._dispatchEvent()
}
if (!isleaf && !hasNodes) { if (node) {
this._loadNodeData((data) => { this.$emit('nodeclick', node)
if (!data.length) { }
node.isleaf = true },
} else { _dispatchEvent() {
this._treeData.push(...data) this.$emit('change', this.selected.slice(0))
this._updateBindData(node) }
} }
this.onSelectedChange(node, node.isleaf) }
}, this._nodeWhere())
return
}
this.onSelectedChange(node, false)
},
updateData(data) {
this._treeData = data.treeData
this.selected = data.selected
if (!this._treeData.length) {
this.loadData()
} else {
//this.selected = data.selected
this._updateBindData()
}
},
onDataChange() {
this.$emit('datachange')
},
onSelectedChange(node, isleaf) {
if (isleaf) {
this._dispatchEvent()
}
if (node) {
this.$emit('nodeclick', node)
}
},
_dispatchEvent() {
this.$emit('change', this.selected.slice(0))
}
}
}
</script> </script>
<style lang="scss"> <style lang="scss">
$uni-primary: #007aff !default; $uni-primary: #007aff !default;
@@ -190,81 +179,80 @@
height: 100%; height: 100%;
} }
.error-text { .error-text {
color: #DD524D; color: #DD524D;
} }
.loading-cover { .loading-cover {
position: absolute; position: absolute;
left: 0; left: 0;
top: 0; top: 0;
right: 0; right: 0;
bottom: 0; bottom: 0;
background-color: rgba(255, 255, 255, .5); background-color: rgba(255, 255, 255, .5);
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
display: flex; display: flex;
/* #endif */ /* #endif */
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
z-index: 1001; z-index: 1001;
} }
.load-more { .load-more {
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
margin: auto; margin: auto;
/* #endif */ /* #endif */
} }
.error-message { .error-message {
background-color: #fff; background-color: #fff;
position: absolute; position: absolute;
left: 0; left: 0;
top: 0; top: 0;
right: 0; right: 0;
bottom: 0; bottom: 0;
padding: 15px; padding: 15px;
opacity: .9; opacity: .9;
z-index: 102; z-index: 102;
} }
/* #ifdef APP-NVUE */ /* #ifdef APP-NVUE */
.selected-area { .selected-area {
width: 750rpx; width: 750rpx;
} }
/* #endif */
/* #endif */ .selected-list {
/* #ifndef APP-NVUE */
display: flex;
flex-wrap: nowrap;
/* #endif */
flex-direction: row;
padding: 0 5px;
border-bottom: 1px solid #f8f8f8;
}
.selected-list { .selected-item {
/* #ifndef APP-NVUE */ margin-left: 10px;
display: flex; margin-right: 10px;
/* #endif */ padding: 12px 0;
flex-direction: row; text-align: center;
flex-wrap: nowrap; /* #ifndef APP-NVUE */
padding: 0 5px; white-space: nowrap;
border-bottom: 1px solid #f8f8f8; /* #endif */
} }
.selected-item { .selected-item-text-overflow {
margin-left: 10px; width: 168px;
margin-right: 10px; /* fix nvue */
padding: 12px 0; overflow: hidden;
text-align: center; /* #ifndef APP-NVUE */
/* #ifndef APP-NVUE */ width: 6em;
white-space: nowrap; white-space: nowrap;
/* #endif */ text-overflow: ellipsis;
} -o-text-overflow: ellipsis;
/* #endif */
.selected-item-text-overflow { }
width: 168px;
/* fix nvue */
overflow: hidden;
/* #ifndef APP-NVUE */
width: 6em;
white-space: nowrap;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
/* #endif */
}
.selected-item-active { .selected-item-active {
border-bottom: 2px solid $uni-primary; border-bottom: 2px solid $uni-primary;
@@ -274,50 +262,50 @@
color: $uni-primary; color: $uni-primary;
} }
.tab-c { .tab-c {
position: relative; position: relative;
flex: 1; flex: 1;
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
display: flex; display: flex;
/* #endif */ /* #endif */
flex-direction: row; flex-direction: row;
overflow: hidden; overflow: hidden;
} }
.list { .list {
flex: 1; flex: 1;
} }
.item { .item {
padding: 12px 15px; padding: 12px 15px;
/* border-bottom: 1px solid #f0f0f0; */ /* border-bottom: 1px solid #f0f0f0; */
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
display: flex; display: flex;
/* #endif */ /* #endif */
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
} }
.is-disabled { .is-disabled {
opacity: .5; opacity: .5;
} }
.item-text { .item-text {
/* flex: 1; */ /* flex: 1; */
color: #333333; color: #333333;
} }
.item-text-overflow { .item-text-overflow {
width: 280px; width: 280px;
/* fix nvue */ /* fix nvue */
overflow: hidden; overflow: hidden;
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
width: 20em; width: 20em;
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; text-overflow: ellipsis;
-o-text-overflow: ellipsis; -o-text-overflow: ellipsis;
/* #endif */ /* #endif */
} }
.check { .check {
margin-right: 5px; margin-right: 5px;

View File

@@ -1,7 +1,7 @@
{ {
"id": "uni-data-picker", "id": "uni-data-picker",
"displayName": "uni-data-picker 数据驱动的picker选择器", "displayName": "uni-data-picker 数据驱动的picker选择器",
"version": "1.0.8", "version": "1.1.2",
"description": "单列、多列级联选择器,常用于省市区城市选择、公司部门选择、多级分类等场景", "description": "单列、多列级联选择器,常用于省市区城市选择、公司部门选择、多级分类等场景",
"keywords": [ "keywords": [
"uni-ui", "uni-ui",