mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-12 20:23:52 +08:00
tt
This commit is contained in:
102
hotgo-uniapp/components/js-checkbox/js-checkbox.vue
Normal file
102
hotgo-uniapp/components/js-checkbox/js-checkbox.vue
Normal file
@@ -0,0 +1,102 @@
|
||||
<template>
|
||||
<view class="u-flex-1">
|
||||
<u-checkbox-group :disabled="disabled" @change="change">
|
||||
<u-checkbox v-model="item.checked" v-for="(item, index) in options.items" :key="index"
|
||||
:name="item.value">{{item.label}}</u-checkbox>
|
||||
</u-checkbox-group>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
/**
|
||||
* 复选框组件
|
||||
* @property {Object} value 用于双向绑定选择框的值,返回选择框的 Value
|
||||
* @property {Boolean} disabled 是否禁用模式,是否只读模式
|
||||
* @property {String} dictType 字典类型,从字典里获取,自动设置 items、itemLabel、itemValue
|
||||
* @property {String} items 列表数据,可接受对象集合,如:[{name: '是', value: '否'}]
|
||||
* @property {String} itemLabel 指定列表数据中的什么属性名作为 option 的标签名,如 name
|
||||
* @property {String} itemValue 指定列表数据中的什么属性名作为 option 的 value 值,如 value
|
||||
* @example <js-select v-model="model.type" dict-type="sys_yes_no"></js-select>
|
||||
* @description Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* @author ThinkGem
|
||||
* @version 2021-3-11
|
||||
*/
|
||||
export default {
|
||||
props: {
|
||||
value: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
dictType: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
items: {
|
||||
type: Array,
|
||||
default() {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
itemLabel: {
|
||||
type: String,
|
||||
default: 'name'
|
||||
},
|
||||
itemValue: {
|
||||
type: String,
|
||||
default: 'value'
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
options: {
|
||||
value: (this.value && this.value.split(',')) || [],
|
||||
items: this.items
|
||||
}
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
value(val, oldVal) {
|
||||
this.options.value = (val && val.split(',')) || [];
|
||||
},
|
||||
items(val, oldVal){
|
||||
this.options.items = val;
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.loadData();
|
||||
},
|
||||
methods: {
|
||||
loadData(){
|
||||
if (this.dictType != ''){
|
||||
this.$u.api.dictData({type: this.dictType}).then(res => {
|
||||
// this.options.items = res;
|
||||
this.selectValue(res.data);
|
||||
});
|
||||
}else{
|
||||
// this.options.items = this.items;
|
||||
this.selectValue(this.items);
|
||||
}
|
||||
},
|
||||
selectValue(items){
|
||||
// 微信小程序,需要延迟下,否则获取不 value 导致无法回显数据
|
||||
this.$nextTick(() => {
|
||||
let vals = this.options.value;
|
||||
for (let i in items){
|
||||
let item = items[i];
|
||||
item.checked = vals.includes(item[this.itemValue]);
|
||||
}
|
||||
this.options.items = items;
|
||||
});
|
||||
},
|
||||
change(val, name){
|
||||
this.$emit('input', (val && val.join(',')) || '');
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
|
||||
</style>
|
||||
69
hotgo-uniapp/components/js-lang/js-lang.vue
Normal file
69
hotgo-uniapp/components/js-lang/js-lang.vue
Normal file
@@ -0,0 +1,69 @@
|
||||
<template>
|
||||
<view v-if="showBtn" class="js-lang" @tap="switchLang">
|
||||
<u-icon size="46" color="warning" :name="lang"></u-icon>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
/**
|
||||
* 语言切换组件
|
||||
* @property {String} title 顶部导航的标题 i18n 编码
|
||||
* @property {Boolean} showBtn 是否显示语言切换按钮
|
||||
* @example <js-lang title="login.title" :showBtn="true"></js-lang>
|
||||
* @description Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* @author ThinkGem
|
||||
* @version 2021-3-11
|
||||
*/
|
||||
export default {
|
||||
props: {
|
||||
title: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
showBtn: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
lang() {
|
||||
return this.$i18n.locale == 'zh_CN' ? 'zh' : 'en';
|
||||
}
|
||||
},
|
||||
created(){
|
||||
this.setBarTitle();
|
||||
},
|
||||
methods: {
|
||||
switchLang() {
|
||||
this.$i18n.locale = this.$i18n.locale == 'zh_CN' ? 'en' : 'zh_CN';
|
||||
this.$u.vuex('vuex_locale', this.$i18n.locale);
|
||||
this.$u.api.lang({lang: this.vuex_locale});
|
||||
this.setBarTitle();
|
||||
},
|
||||
setBarTitle (){
|
||||
uni.setNavigationBarTitle({
|
||||
title: this.$t(this.title)
|
||||
});
|
||||
uni.setTabBarItem({
|
||||
index: 0,
|
||||
text: this.$t('nav.msg')
|
||||
});
|
||||
uni.setTabBarItem({
|
||||
index: 1,
|
||||
text: this.$t('nav.home')
|
||||
});
|
||||
uni.setTabBarItem({
|
||||
index: 2,
|
||||
text: this.$t('nav.user')
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.js-lang {
|
||||
position: absolute;
|
||||
z-index: 10000;
|
||||
top: 15px;
|
||||
right: 15px;
|
||||
}
|
||||
</style>
|
||||
93
hotgo-uniapp/components/js-radio/js-radio.vue
Normal file
93
hotgo-uniapp/components/js-radio/js-radio.vue
Normal file
@@ -0,0 +1,93 @@
|
||||
<template>
|
||||
<view class="u-flex-1">
|
||||
<u-radio-group v-model="options.value" :disabled="disabled" @change="change">
|
||||
<u-radio v-for="(item, index) in options.items" :key="index"
|
||||
:name="item.value"> {{item.label}}</u-radio>
|
||||
</u-radio-group>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
/**
|
||||
* 单选框组件
|
||||
* @property {Object} value 用于双向绑定选择框的值,返回选择框的 Value
|
||||
* @property {Boolean} disabled 是否禁用模式,是否只读模式
|
||||
* @property {String} dictType 字典类型,从字典里获取,自动设置 items、itemLabel、itemValue
|
||||
* @property {String} items 列表数据,可接受对象集合,如:[{name: '是', value: '否'}]
|
||||
* @property {String} itemLabel 指定列表数据中的什么属性名作为 option 的标签名,如 name
|
||||
* @property {String} itemValue 指定列表数据中的什么属性名作为 option 的 value 值,如 value
|
||||
* @example <js-radio v-model="model.type" dict-type="sys_yes_no"></js-radio>
|
||||
* @description Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* @author ThinkGem
|
||||
* @version 2021-3-11
|
||||
*/
|
||||
export default {
|
||||
props: {
|
||||
value: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
dictType: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
items: {
|
||||
type: Array,
|
||||
default() {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
itemLabel: {
|
||||
type: String,
|
||||
default: 'name'
|
||||
},
|
||||
itemValue: {
|
||||
type: String,
|
||||
default: 'value'
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
options: {
|
||||
value: this.value,
|
||||
items: this.items
|
||||
}
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
value(val, oldVal) {
|
||||
this.options.value = val;
|
||||
},
|
||||
items(val, oldVal){
|
||||
this.options.items = val;
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.loadData();
|
||||
},
|
||||
methods: {
|
||||
loadData(){
|
||||
if (this.dictType !== ''){
|
||||
this.$u.api.dictData({type: this.dictType}).then(res => {
|
||||
if (typeof res === 'object' && res.result === 'login'){
|
||||
return;
|
||||
}
|
||||
this.options.items = res.data;
|
||||
});
|
||||
}else{
|
||||
this.options.items = this.items;
|
||||
}
|
||||
},
|
||||
change(val){
|
||||
// console.log(val);
|
||||
this.$emit('input', val);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
|
||||
</style>
|
||||
215
hotgo-uniapp/components/js-select/js-select.vue
Normal file
215
hotgo-uniapp/components/js-select/js-select.vue
Normal file
@@ -0,0 +1,215 @@
|
||||
<template>
|
||||
<view class="u-flex-1">
|
||||
<u-input :type="disabled?'input':'select'"
|
||||
v-model="options.label"
|
||||
:disabled="disabled"
|
||||
:placeholder="placeholder"
|
||||
:select-open="options.open"
|
||||
@click="inputClick"
|
||||
></u-input>
|
||||
<u-select :mode="options.mode"
|
||||
v-model="options.open"
|
||||
:list="options.items"
|
||||
:label-name="options.itemLabel"
|
||||
:value-name="options.itemValue"
|
||||
:default-value="options.currentIndex"
|
||||
@confirm="selectConfirm"
|
||||
style="width: 100%"
|
||||
></u-select>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
/**
|
||||
* 下拉选择组件
|
||||
* @property {Object} value 用于双向绑定选择框的值,返回选择框的 Value
|
||||
* @property {Boolean} disabled 是否禁用模式,是否只读模式
|
||||
* @property {String} tree 是否为树结构(默认 false)
|
||||
* @property {String} placeholder 选择框的占位符,提示文字
|
||||
* @property {String} dictType 字典类型,从字典里获取,自动设置 items、itemLabel、itemValue
|
||||
* @property {String} items 列表数据,可接受对象集合,如:[{name: '是', value: '否'}]
|
||||
* @property {String} itemLabel 指定列表数据中的什么属性名作为 option 的标签名,如 name
|
||||
* @property {String} itemValue 指定列表数据中的什么属性名作为 option 的 value 值,如 value
|
||||
* @example <js-select v-model="model.type" dict-type="sys_yes_no"></js-select>
|
||||
* @description Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* @author ThinkGem
|
||||
* @version 2021-3-11
|
||||
*/
|
||||
export default {
|
||||
props: {
|
||||
value: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
labelValue: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: '请选择选项'
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
tree: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
dictType: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
multiple: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
items: {
|
||||
type: Array,
|
||||
default() {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
itemLabel: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
itemValue: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
returnFullName: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
returnFullNameSplit: {
|
||||
type: String,
|
||||
default: '/'
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
options: {
|
||||
value: this.value,
|
||||
label: this.labelValue,
|
||||
open: false,
|
||||
mode: 'single-column',
|
||||
items: this.items,
|
||||
itemLabel: this.itemLabel || 'name',
|
||||
itemValue: this.itemValue || (this.tree ? 'id' : 'value'),
|
||||
currentIndex: [],
|
||||
indexMap: {}
|
||||
}
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
value(val, oldVal) {
|
||||
this.options.value = val;
|
||||
},
|
||||
labelValue(val, oldVal) {
|
||||
this.options.label = val;
|
||||
},
|
||||
items(val, oldVal){
|
||||
this.setItems(val);
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.loadData();
|
||||
},
|
||||
methods: {
|
||||
loadData() {
|
||||
if (this.dictType != ''){
|
||||
this.$u.api.dictData({type: this.dictType}).then(res => {
|
||||
if (typeof res === 'object' && res.result === 'login'){
|
||||
return;
|
||||
}
|
||||
this.setItems(res.data);
|
||||
});
|
||||
}else{
|
||||
this.setItems(this.items);
|
||||
}
|
||||
},
|
||||
setItems(res){
|
||||
if (this.tree){
|
||||
this.options.mode = 'mutil-column-auto';
|
||||
res = this.convertTree(res);
|
||||
}
|
||||
this.options.items = res;
|
||||
this.selectValue();
|
||||
},
|
||||
selectValue() {
|
||||
// 微信小程序,需要延迟下,否则获取不 value 导致无法回显数据
|
||||
this.$nextTick(() => {
|
||||
if (!this.options.value) {
|
||||
return;
|
||||
}
|
||||
for (let i in this.options.items){
|
||||
let item = this.options.items[i];
|
||||
this.options.indexMap[item[this.options.itemValue]] = Number(i);
|
||||
if (item[this.options.itemValue] == this.options.value){
|
||||
// this.options.value = item[this.options.itemValue];
|
||||
this.options.label = item[this.options.itemLabel];
|
||||
if (!this.tree){
|
||||
this.options.currentIndex = [this.options.indexMap[this.options.value]];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
convertTree(data) {
|
||||
let i, l, key = "id", parentKey = "pId", childKey = "children";
|
||||
if (Object.prototype.toString.apply(data) === "[object Array]") {
|
||||
let treeData = [], map = [];
|
||||
for (i=0, l=data.length; i<l; i++) {
|
||||
map[data[i][key]] = data[i];
|
||||
}
|
||||
for (i=0, l=data.length; i<l; i++) {
|
||||
if (map[data[i][parentKey]] && data[i][key] != data[i][parentKey]) {
|
||||
if (!map[data[i][parentKey]][childKey]){
|
||||
map[data[i][parentKey]][childKey] = [];
|
||||
}
|
||||
map[data[i][parentKey]][childKey].push(data[i]);
|
||||
} else {
|
||||
treeData.push(data[i]);
|
||||
}
|
||||
}
|
||||
return treeData;
|
||||
}else {
|
||||
return [data];
|
||||
}
|
||||
},
|
||||
inputClick() {
|
||||
if (!this.disabled){
|
||||
this.options.open = true;
|
||||
}
|
||||
},
|
||||
selectConfirm(items) {
|
||||
let values = [], labels = [], currentIndexes = [];
|
||||
for (let i in items){
|
||||
let item = items[i];
|
||||
values.push(String(item.value).replace(/^u_/g,''));
|
||||
labels.push(String(item.label));
|
||||
if (!this.tree){
|
||||
currentIndexes.push(this.options.indexMap[item.value])
|
||||
}
|
||||
}
|
||||
this.options.value = values.length > 0 ? values[values.length-1] : '';
|
||||
if (this.returnFullName){
|
||||
this.options.label = labels.join(this.returnFullNameSplit);
|
||||
}else{
|
||||
this.options.label = labels.length > 0 ? labels[labels.length-1] : '';
|
||||
}
|
||||
if (!this.tree){
|
||||
this.options.currentIndex = currentIndexes;
|
||||
}
|
||||
//console.log(this.options.value, this.options.label)
|
||||
this.$emit('input', this.options.value);
|
||||
this.$emit('label-input', this.options.label);
|
||||
this.$emit('confirm', this.options.value, this.options.label);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
|
||||
</style>
|
||||
278
hotgo-uniapp/components/js-uploadfile/js-uploadfile.vue
Normal file
278
hotgo-uniapp/components/js-uploadfile/js-uploadfile.vue
Normal file
@@ -0,0 +1,278 @@
|
||||
<template>
|
||||
<view class="u-flex-1">
|
||||
<u-upload width="160" height="160" ref="uUpload"
|
||||
:action="options.action"
|
||||
:header="options.header"
|
||||
:form-data="options.formData"
|
||||
:name="options.name"
|
||||
:max-count="maxCount"
|
||||
:auto-upload="true"
|
||||
:deletable="deletable"
|
||||
:before-upload="beforeUpload"
|
||||
@on-success="uploadSuccess"
|
||||
@on-uploaded="uploadUploaded"
|
||||
:before-remove="beforeRemove"
|
||||
@on-remove="uploadRemove"
|
||||
></u-upload>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
import SparkMD5 from '@/common/spark-md5.js';
|
||||
/**
|
||||
* 文件上传组件组件
|
||||
* @property {Object} value 使用 v-model="this.model" 指定表单的 model 对象(存放文件上传编号信息)
|
||||
* @property {String} bizKey 业务表的主键值(与附件关联的业务数据)【可选】如果不设置,则获取 value.id 作为主键
|
||||
* @property {String} bizType 业务表的上传类型(全网唯一,推荐格式:实体名_上传类型,例如,意见反馈图片:appComment_image)
|
||||
* @property {String} uploadType 上传文件类型:image,目前移动端仅支持上传图片
|
||||
* @property {String} imageMaxWidth 图片压缩,最大宽度(uploadType为image生效),设置-1代表不做任何处理
|
||||
* @property {String} imageMaxHeight 图片压缩,最大宽度(uploadType为image生效),设置-1代表不做任何处理
|
||||
* @property {String} maxCount 最大上传个数,默认 52 个,如果设置为 0 可以当做【只读模式】使用
|
||||
* @example <js-uploadfile v-model="model.otherData" :biz-key="model.id" biz-type="testData_image"></js-uploadfile>
|
||||
* @description Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* @author ThinkGem
|
||||
* @version 2021-3-11
|
||||
*/
|
||||
export default {
|
||||
props: {
|
||||
value: {
|
||||
type: Object,
|
||||
default() {
|
||||
return {}
|
||||
}
|
||||
},
|
||||
bizKey: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
bizType: {
|
||||
type: String,
|
||||
default: 'images'
|
||||
},
|
||||
uploadType: {
|
||||
type: String,
|
||||
default: 'image'
|
||||
},
|
||||
imageMaxWidth: {
|
||||
type: [String, Number],
|
||||
default: 1024
|
||||
},
|
||||
imageMaxHeight: {
|
||||
type: [String, Number],
|
||||
default: 768
|
||||
},
|
||||
maxCount: {
|
||||
type: [String, Number],
|
||||
default: 52
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
options: {
|
||||
value: {},
|
||||
action: '',
|
||||
header: {},
|
||||
formData: {
|
||||
fileMd5: '',
|
||||
fileName: '',
|
||||
bizKey: this.bizKey || (this.value && this.value.id) || '',
|
||||
bizType: this.bizType,
|
||||
uploadType: this.uploadType,
|
||||
imageMaxWidth: this.imageMaxWidth,
|
||||
imageMaxHeight: this.imageMaxHeight
|
||||
},
|
||||
name: 'file',
|
||||
// 文件上传的 id 数组
|
||||
fileUploadIds: [],
|
||||
// 文件删除的 id 数组
|
||||
fileUploadDelIds: []
|
||||
},
|
||||
deletable: true
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
value(val, oldVal) {
|
||||
this.options.value = val;
|
||||
},
|
||||
maxCount(val, oldVal) {
|
||||
this.refreshStatus();
|
||||
},
|
||||
bizKey(val, oldVal) {
|
||||
this.options.formData.bizKey = val;
|
||||
this.loadData();
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.refreshStatus();
|
||||
this.options.action = this.vuex_config.baseUrl + this.vuex_config.adminPath + '/file/upload';
|
||||
this.options.formData = Object.assign(this.options.formData, this.formData);
|
||||
this.loadData();
|
||||
},
|
||||
methods: {
|
||||
// 刷新是否只读状态
|
||||
refreshStatus(){
|
||||
if (this.maxCount <= 0){
|
||||
this.deletable = false;
|
||||
}
|
||||
},
|
||||
// 已上传的文件回显到上传组件
|
||||
loadData(){
|
||||
if (this.options.formData.bizKey != ''){
|
||||
let baseUrl = this.vuex_config.baseUrl;
|
||||
let adminPath = this.vuex_config.adminPath;
|
||||
this.$u.post(adminPath + '/file/fileList', {
|
||||
bizKey: this.options.formData.bizKey,
|
||||
bizType: this.options.formData.bizType,
|
||||
}).then(res => {
|
||||
let lists = [];
|
||||
if (!(typeof res === 'object' && (res.result === 'login' || res.result === 'false'))){
|
||||
for (let i in res){
|
||||
let f = res[i];
|
||||
lists.push({
|
||||
url: baseUrl + f.fileUrl,
|
||||
fileUploadId: f.id,
|
||||
progress: 100,
|
||||
error: false
|
||||
});
|
||||
}
|
||||
}
|
||||
// console.log(lists)
|
||||
this.$refs.uUpload.lists = lists;
|
||||
this.uploadRefreshIds(lists);
|
||||
});
|
||||
}
|
||||
},
|
||||
// 上传之前,验证秒传、是否继续上传等
|
||||
beforeUpload(index, lists) {
|
||||
let self = this;
|
||||
let item = lists[index];
|
||||
let upload = this.upload;
|
||||
let formData = this.options.formData;
|
||||
let baseUrl = this.vuex_config.baseUrl;
|
||||
let adminPath = this.vuex_config.adminPath;
|
||||
self.$u.http.interceptor.request(this.options);
|
||||
return new Promise((resolve, reject) => {
|
||||
try{
|
||||
function uploadFile(arrayBuffer){
|
||||
let buffer = arrayBuffer;
|
||||
let size = 10 * 1024 * 1024;
|
||||
let spark = new SparkMD5.ArrayBuffer();
|
||||
if (buffer.byteLength > size){
|
||||
spark.append(buffer.slice(0, size));;
|
||||
}else{
|
||||
spark.append(buffer);
|
||||
}
|
||||
formData.fileEntityId = '';
|
||||
formData.fileUploadId = '';
|
||||
formData.fileMd5 = spark.end();
|
||||
formData.fileName = item.file.name;
|
||||
// console.log('formData' + JSON.stringify(formData));
|
||||
self.$u.post(adminPath + '/file/upload', formData).then(res => {
|
||||
// console.log(res)
|
||||
// 文件已经上传,启用秒传
|
||||
if (res.result == 'true' && res.fileUpload){
|
||||
item.fileUploadId = res.fileUpload.id;
|
||||
item.progress = 100;
|
||||
item.error = false;
|
||||
reject(res);
|
||||
}
|
||||
// 文件未上传过,继续上传文件
|
||||
else if (res.fileUploadId && res.fileEntityId){
|
||||
formData.fileUploadId = res.fileUploadId;
|
||||
formData.fileEntityId = res.fileEntityId;
|
||||
item.fileUploadId = res.fileUploadId;
|
||||
resolve();
|
||||
}
|
||||
// 未知错误,提示服务端返回的信息
|
||||
else {
|
||||
uni.showModal({title: '提示', content: res.message });
|
||||
reject(res);
|
||||
}
|
||||
}).catch(err => {
|
||||
console.error(err);
|
||||
reject(err);
|
||||
})
|
||||
}
|
||||
// #ifdef APP-PLUS
|
||||
plus.io.requestFileSystem(plus.io.PRIVATE_WWW, function(fs){
|
||||
fs.root.getFile(item.url, {create: false}, function(fileEntry){
|
||||
fileEntry.file(function(file){
|
||||
// console.log("getFile:" + JSON.stringify(file))
|
||||
item.file.name = file.name;
|
||||
var fileReader = new plus.io.FileReader();
|
||||
fileReader.readAsText(file, 'utf-8');
|
||||
fileReader.onloadend = function(evt) {
|
||||
uploadFile(evt.target.result);
|
||||
}
|
||||
fileReader.onerror = function(error) {
|
||||
reject(error);
|
||||
}
|
||||
}, reject);
|
||||
}, reject);
|
||||
} );
|
||||
// #endif
|
||||
// #ifndef APP-PLUS
|
||||
uni.request({
|
||||
url: item.url,
|
||||
responseType: 'arraybuffer',
|
||||
complete: res => {
|
||||
// console.log(res)
|
||||
if (res.statusCode == 200) {
|
||||
uploadFile(res.data);
|
||||
}else{
|
||||
reject(res);
|
||||
}
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
}catch(err){
|
||||
console.error(err);
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
},
|
||||
// 上传成功一个,就写进 fileUploadIds
|
||||
uploadSuccess(data, index, lists, name){
|
||||
let item = lists[index];
|
||||
this.options.fileUploadIds.push(item.fileUploadId);
|
||||
},
|
||||
// 全部上传后,刷新 fileUploadIds、fileUploadDelIds
|
||||
uploadUploaded(lists, name) {
|
||||
this.uploadRefreshIds(lists);
|
||||
},
|
||||
// 移除之前获取删除的 fileUploadId,写进 fileUploadDelIds
|
||||
beforeRemove(index, lists){
|
||||
let item = lists[index];
|
||||
if (item.fileUploadId){
|
||||
this.options.fileUploadDelIds.push(item.fileUploadId);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
// 移除之后,刷新 fileUploadIds、fileUploadDelIds
|
||||
uploadRemove(index, lists){
|
||||
this.uploadRefreshIds(lists);
|
||||
},
|
||||
// 刷新 fileUploadIds、fileUploadDelIds
|
||||
uploadRefreshIds(lists, name) {
|
||||
let fileUploadIds = [];
|
||||
lists.forEach(item => {
|
||||
if (item.fileUploadId && item.progress == 100){
|
||||
fileUploadIds.push(item.fileUploadId);
|
||||
}
|
||||
});
|
||||
this.options.fileUploadIds = fileUploadIds;
|
||||
// console.log('fileUploadIds', this.options.fileUploadIds)
|
||||
// console.log('fileUploadDelIds', this.options.fileUploadDelIds)
|
||||
// 将上传和删除的 id 回传给 model
|
||||
let formData = this.options.formData;
|
||||
let fileParams = this.options.value || {};
|
||||
fileParams[formData.bizType] = this.options.fileUploadIds.join(',');
|
||||
fileParams[formData.bizType+'__del'] = this.options.fileUploadDelIds.join(',');
|
||||
this.options.value = fileParams;
|
||||
this.$emit('input', Object.assign(this.options.value, this.value));
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user