<template>
|
<view class="view-data-new-dataobj">
|
<uni-forms ref="baseForm" :modelValue="form" label-position="top" label-width="320">
|
<view class="uni-group-item" v-for="(group,index) in showStyle" :key="group.attrgroup_name">
|
<view class="uni-panel-title" @click="group.open = !group.open">
|
<text class="uni-title-icon" :style="{ backgroundColor: toHexColor(group.def?.bk_color) }"><text
|
class="uni-icon" :class="group.def?.img_font_style"></text></text>
|
<text class="uni-title-text">{{group.attrgroup_name}}</text>
|
<view class="uni-panel-icon-btn">
|
<uni-icons color="#000" type="down" size="18" />
|
</view>
|
</view>
|
<view v-if="group.open" class="uni-head-style" :class="hiddenAttrs.includes(attr.attr)? 'uni-hidden':''"
|
v-for="(attr,i) in group.attrs" :key="`attr-${index}-${i}`">
|
<uni-forms-item :label="attrLabel(attr)" :required="attrRequired(attr)" :error="errTip[attr.attr]">
|
<view class="input-wrapper">
|
<input v-if="attr.type == 'input'" v-model="form[attr.attr]" :ref="`ref${attr.attr}`"
|
:disabled="!attr.edit" @on-blur="onChange(attr)" />
|
<textarea v-if="attr.type == 'textarea'" v-model="form[attr.attr]" :ref="`ref${attr.attr}`"
|
:disabled="!attr.edit" @on-blur="onChange(attr)" />
|
<input v-else-if="attr.type == 'int'" v-model="form[attr.attr]" type="number"
|
:ref="`ref${attr.attr}`" :disabled="!attr.edit" @on-blur="onChange(attr)" />
|
<input v-else-if="attr.type == 'float'" v-model="form[attr.attr]" type="digit"
|
:ref="`ref${attr.attr}`" :disabled="!attr.edit" @on-blur="onChange(attr)" />
|
<switch v-else-if="attr.type == 'checkbox'" :checked="form[attr.attr]"
|
:ref="`ref${attr.attr}`" :disabled="!attr.edit" @change="form[attr.attr]=checked">
|
</switch>
|
<uni-data-select id="dv_select" v-if="attr.type == 'select'"
|
:class="attr.edit?'':'input-disabled'" v-model="form[attr.attr]"
|
:localdata="dictList[attr.attr]" @change="onChange(attr)" :disabled="!attr.edit"
|
clear></uni-data-select>
|
<picker v-else-if="attr.type == 'date'" mode="date" style="width: 100%"
|
:value="form[attr.attr]" :ref="`ref${attr.attr}`" :disabled="!attr.edit"
|
@change="form[attr.attr]=value" />
|
<picker v-else-if="attr.type == 'time'" mode="time" style="width: 100%"
|
:value="form[attr.attr]" :ref="`ref${attr.attr}`" :disabled="!attr.edit"
|
@change="form[attr.attr]=value" />
|
<text v-else-if="attr.type == 'ref-psn'">{{form[attr.attr]}}</text>
|
</view>
|
</uni-forms-item>
|
</view>
|
</view>
|
<view class="uni-group-item" v-if="hasAttach">
|
<view class="uni-panel-title" @click="clickShowAttach">
|
<text class="uni-title-icon" :style="{ backgroundColor: '#aaa' }"><text
|
class="uni-icon fs-attach"></text></text>
|
<text class="uni-title-text">附件</text>
|
<text class="uni-panel-icon-btn fs-floder" v-if="isCanSelFile" style="margin-left: 4px;"
|
@click.prevent.stop="clickSelFile"></text>
|
<text class="uni-panel-icon-btn fs-camera" v-if="isMobilePlatform" style="margin-left: 4px;"
|
@click.prevent.stop="clickCamera"></text>
|
<view class="uni-panel-icon-btn">
|
<uni-icons color="#000" type="down" size="18" />
|
</view>
|
</view>
|
<view v-if="showAttach" class="uni-panel-upfile">
|
<view class="uni-panel-upfile-item" v-for="(item,index) in attachList"
|
:style="{background:item.color}" :key="index" @longpress="longpressPic(item,index)"
|
@click="openAattachFile(item)">
|
<view v-if="!(item.isImg || item.isVideo)|| (( item.isImg) && !item.path)"
|
class="uni-panel-upfile-item-name">{{item.name}}</view>
|
<text v-if="!(item.isImg || item.isVideo)"
|
class="uni-panel-upfile-item-size">{{item.sizestr}}</text>
|
<image v-if=" (item.isImg && item.path)" class="uni-panel-upfile-img" :src="item.path"
|
mode="widthFix" />
|
<jvideo v-if="item.isVideo && item.path" :url="item.path" width="192rpx" height="192rpx"
|
:len="10"></jvideo>
|
<text v-if="item.errMsg" class="uni-panel-icon fs-wrong"
|
style="position: absolute; bottom:5rpx; right: 5rpx; color: #fd3c46;"
|
@click="onErrInfo(item.errMsg)"></text>
|
<!-- #ifdef MP-WEIXIN -->
|
<circleProgressBar v-if="item.isUploading" style="position: absolute; top: 50rpx; left: 50rpx;"
|
:size="100" :border_width="16" border_back_color='#ccc' background='#ffffff80'
|
:pro="item.percent/100" />
|
<!-- #endif-->
|
</view>
|
|
</view>
|
</view>
|
</uni-forms>
|
<view class="uni-panel-bottom-button">
|
<button class="uni-panel-button" @click="submitForm">提交</button>
|
</view>
|
<view class="uni-panel-safe-bottom" :style="{height:safeAreaBottom + 'px'}" />
|
<uni-popup ref="popupFileSel" background-color="#fff">
|
<view class="popup-content" style="padding: 2px 4px 12px;">
|
<view class="popup-content_menu-item" style="border-bottom: 1px solid #eeeeee;"
|
@click="clickSelMessageFile">从会话中选择</view>
|
<view class="popup-content_menu-item" style="border-bottom: 1px solid #eeeeee;"
|
@click="clickSelLocalFile">从本地文件选择</view>
|
<view class="popup-content_menu-item" @click="closeFileSelPopup">取消</view>
|
</view>
|
</uni-popup>
|
</view>
|
</template>
|
|
<script>
|
import TaskInit from "@/common/extend.js"
|
import {
|
showModal,
|
showToast,
|
showLoading,
|
hideLoading
|
} from "@/common/Page.js"
|
import dataObjItem from "@/components/dataobj-item.vue"
|
// import {
|
// getDictValue,
|
// getClassAttr,
|
// getClsUIStyleInfo,
|
// getClassAttrAttach,
|
// getFileUrlS,
|
// downloadTaskFile,
|
// getDataAttrList,
|
// dataObjRunCustomEvent,
|
// getUploadType,
|
// getUploadUrlMinio,
|
// uploadTaskFileMinio,
|
// writeFileToMinioDB,
|
// uploadTaskFile,
|
// addClassAttr,
|
// updateClassAttr,
|
// invokeEvent
|
|
// } from "@/common/api/app.js"
|
import {
|
loginWxQy
|
|
} from "@/api/index.js"
|
import jvideo from '@/components/j-video.vue'
|
import circleProgressBar from '@/components/circle-progress-bar/circle-progress-bar.vue'
|
export default {
|
name: "pageDataNewDataObj",
|
components: {
|
jvideo,
|
circleProgressBar,
|
},
|
data() {
|
return {
|
styleDef: {},
|
showStyle: [],
|
attrList: [],
|
hiddenAttrs: [],
|
attachList: [],
|
delFileList: [],
|
dictList: [],
|
clsName: "",
|
form: {},
|
errTip: {},
|
enviroment: {},
|
hasAttach: false,
|
isMobilePlatform: true,
|
isCanSelFile: true,
|
showAttach: true,
|
globalAttr: "",
|
extInfo: {},
|
safeAreaBottom: getApp().globalData.safeAreaBottom,
|
}
|
},
|
computed: {
|
formAttrObj() {
|
return this.form;
|
},
|
initialEvent() {
|
let event = this.styleDef.Event?.find((e) => e.event_id == "initial");
|
return {
|
id: event?.scrip_id,
|
name: event?.scrip_name,
|
};
|
},
|
},
|
methods: {
|
setData: function(obj) {
|
let that = this;
|
let keys = [];
|
let val, data;
|
|
Object.keys(obj).forEach(function(key) {
|
keys = key.split(".");
|
val = obj[key];
|
data = that.$data;
|
keys.forEach(function(key2, index) {
|
if (index + 1 == keys.length) {
|
that.$set(data, key2, val);
|
} else {
|
if (!data[key2]) {
|
that.$set(data, key2, {});
|
}
|
}
|
data = data[key2];
|
});
|
});
|
},
|
async loadData() {
|
this.hasAttach = this.options.hasAttach
|
this.extInfo = {
|
function: this.options.defCode,
|
cls_id: this.options.clsId,
|
obj_id: "",
|
panel: {},
|
button: this.options.button || "",
|
button_name: this.options.buttonName || "",
|
master: {
|
cls_id: this.options.clsId,
|
obj_id: ""
|
},
|
key: {
|
attr: "",
|
value: ""
|
}
|
}
|
await this.loadForm()
|
await this.loadFormData()
|
this.hideFormItems([])
|
let attrs = [];
|
this.showStyle.forEach((group) => {
|
group.attrs.forEach(async (attr) => {
|
attrs.push({
|
attr: attr.attr,
|
val: ""
|
})
|
})
|
})
|
|
dataObjRunCustomEvent(this.options.clsId, this.initialEvent.id, JSON.stringify(attrs), JSON.stringify(
|
this
|
.extInfo), "", this.globalAttr).then((res) => {
|
|
const resJson = JSON.parse(res)
|
let curIndex = (resJson.action || []).findIndex((item2, index, arr) => {
|
return item2.action_type == "set_dlg_attr";
|
})
|
if (curIndex >= 0) {
|
const value = resJson.action[curIndex].value;
|
(value || []).forEach((item) => {
|
this.form[item.attr] = item.value
|
})
|
|
}
|
console.log("dataObjRunCustomEvent", resJson, this.form)
|
// let curIndex = (resJson.action || []).findIndex((item2, index, arr) => {
|
// return item2.action_type == "set_global_attr";
|
// })
|
// if (curIndex >= 0) {
|
// this.globalAttr = resJson.action[curIndex].value
|
|
// }
|
}).catch((err) => {
|
console.log("dataObjRunCustomEvent fail", err)
|
})
|
},
|
async loadFormData() {
|
try {
|
if (this.options.objId) {
|
const clsAttr = await getClassAttr(this.options.clsId, this.options.objId)
|
const objAttr = clsAttr.ObjAttr || []
|
const clsAttrAttach = await getClassAttrAttach(this.options.clsId, this.options.objId)
|
this.showStyle.forEach((group) => {
|
group.attrs.forEach((attr) => {
|
let info = objAttr.find((o) => o.Name == attr.attr);
|
if (info) {
|
if (attr.type == "ref-psn")
|
this.form[attr.attr] = {
|
id: info.Value.split(";")[0],
|
name: info.Value.split(";")[1],
|
type: 0,
|
};
|
else this.form[attr.attr] = info.Value;
|
}
|
});
|
});
|
clsAttrAttach.forEach((ele, index) => {
|
let upfile = {
|
isUploading: false,
|
fileserver: ele.FileServer,
|
percent: 100,
|
fileId: ele.FileID,
|
fileMD5: ele.FileMD5 || "",
|
name: ele.FileName,
|
size: ele.FileSize,
|
path: ele.Url,
|
id:ele.ID,
|
color: TaskInit.fileUtils.getTypeBgColor(ele.FileName),
|
sizestr: TaskInit.fileUtils.getFileSizeStr(ele.FileSize)
|
};
|
if (TaskInit.fileUtils.isPictureType(ele.FileName)) //文档
|
{
|
upfile.isImg = true
|
}
|
if (TaskInit.fileUtils.isVideoType(ele.FileName)) //文档
|
{
|
|
upfile.isVideo = true
|
}
|
|
const attachs = this.attachList
|
attachs.push(upfile)
|
this.setData({
|
attachList: attachs,
|
})
|
})
|
}
|
} catch (ex) {
|
let tip = typeof ex == "string" ? ex : ex.message;
|
console.log(`装载数据信息失败`, ex);
|
showModal(tip, "出错", false, false)
|
}
|
},
|
async loadForm() {
|
var _this = this;
|
|
try {
|
this.form = {};
|
this.errTip = {};
|
const info = await getClsUIStyleInfo(_this.options.clsId, 2, _this.options.editName)
|
this.attrList = await getDataAttrList(_this.options.clsId)
|
const show_style = info.StyleDef.show_style || []
|
this.styleDef = info.StyleDef
|
//
|
|
// await getDictValue( "数据生命周期");
|
// console.log("getClsUIStyleInfo", info)
|
this.showStyle = show_style
|
await Promise.all(
|
show_style.map(async (group) => {
|
let group_def = this.attrList.find(
|
(a) => a.Name == group.attrgroup_name
|
);
|
group.def = {
|
bk_color: group_def.BkColor,
|
img_font_style: "fs-mobox_log",
|
};
|
|
await Promise.all(
|
group.attrs.map(async (attr) => {
|
let attr_def = group_def.Attr.find(
|
(a) => a.Name == attr.attr
|
);
|
// “小窗口”中“显示配置”指定的属性在当前数据类中已变更,无法得到相应的定义
|
if (!attr_def) {
|
const tip =
|
`当前数据类“${this.clsName}(${this.clsId})”中找不到名为“${attr.name}(${attr.attr})”的属性`
|
showModal(tip, "出错", false, false)
|
return;
|
}
|
attr.def = attr_def;
|
attr.type = this.getAttrType(attr.def);
|
|
this.form[attr.attr] = this.defaultValue(attr.type);
|
this.errTip[attr.attr] = "";
|
|
if (attr.type == "select") {
|
if (attr.def.DictName) {
|
let res = await getDictValue(attr.def
|
.DictName);
|
let dictList = res || res;
|
|
this.dictList[attr.attr] = dictList.map((dict) => {
|
return {
|
text: dict.Value || dict.Name,
|
value: dict.Name
|
}
|
});
|
let dictName = "";
|
if (dictList?.length > 0) {
|
let defaultValue = dictList.find(
|
(d) => d.IsDefault == 1
|
)?.Name;
|
if (defaultValue) dictName = defaultValue;
|
else dictName = dictList[0].Name;
|
}
|
this.form[attr.attr] = dictName;
|
} else {
|
this.dictList[attr.attr] = [];
|
this.form[attr.attr] = "";
|
}
|
}
|
})
|
);
|
})
|
);
|
|
console.log(`装载显示数据信息`, info, this.showStyle);
|
} catch (ex) {
|
let tip = typeof ex == "string" ? ex : ex.message;
|
console.log(`装载显示数据信息失败`, ex);
|
showModal(tip, "出错", false, false)
|
}
|
},
|
hideFormItems(attrs) {
|
let attrList = [];
|
this.showStyle.forEach((group) => attrList.push(...group.attrs));
|
this.hiddenAttrs = [
|
...attrList.filter((a) => (a.hidden === true || a.hidden === "True")).map((a) => a.attr),
|
...attrs
|
.filter((attr) => attr.attr in this.form && (attr.show === false || attr.show === "False"))
|
.map((attr) => attr.attr),
|
];
|
//console.log("hideFormItems", attrList, this.hiddenAttrs)
|
},
|
setFormAllValues(attrs) {
|
this.$emit("on-set-all-value", attrs);
|
},
|
isValid() {
|
let flag = true;
|
this.showStyle.forEach((group) => {
|
group.attrs.forEach((attr) => {
|
let val = this.form[attr.attr];
|
if (attr.def.type == "日期") val = dayjs(val).format("YYYY-MM-DD");
|
if (attr.def.not_empty == 1 && isNullOrEmpty(val)) {
|
this.errTip[attr.attr] = `${attr.name}不能为空`;
|
flag = false;
|
if (this.$refs[`ref${attr.attr}`][0].focus)
|
this.$refs[`ref${attr.attr}`][0].focus();
|
else if (this.$refs[`ref${attr.attr}`][0].$el.focus)
|
this.$refs[`ref${attr.attr}`][0].$el.focus();
|
}
|
});
|
});
|
return flag;
|
},
|
getAttrType(def) {
|
let type = def?.Type;
|
let height = def?.Height;
|
let ctrlType = "";
|
this.showStyle?.forEach((group) => {
|
ctrlType = group.attrs?.find((a) => a.attr == def.Name)?.ctrl_type;
|
});
|
|
let guid = ["GUID"];
|
let char = ["字符串", "可变长字符串", "char", "varchar"];
|
let select = ["字典-字符串", "字典-整数", "dict-char", "dict-int"];
|
let int = ["整数", "int"];
|
let float = ["浮点数", "float"];
|
let bool = ["布尔值", "bool"];
|
let date = ["日期", "date"];
|
let time = ["时间", "datetime"];
|
let refPsn = ["引用人员", "user"];
|
|
console.log("getAttrType", type, def)
|
if (guid.includes(type) || char.includes(type))
|
return ctrlType == "dropdown" ?
|
"select" :
|
height == 2 ?
|
"textarea" :
|
height == 3 ?
|
"textarea" :
|
"input";
|
else if (select.includes(type)) return "select";
|
else if (int.includes(type)) return "int";
|
else if (float.includes(type)) return "float";
|
else if (bool.includes(type)) return "checkbox";
|
else if (date.includes(type)) return "date";
|
else if (time.includes(type)) return "time";
|
else if (refPsn.includes(type)) return "ref-psn";
|
else return "unknown";
|
},
|
defaultValue(type) {
|
let value = undefined;
|
switch (type) {
|
case "input":
|
value = "";
|
break;
|
case "select":
|
value = "";
|
break;
|
case "int":
|
value = "";
|
break;
|
case "float":
|
value = 0.0;
|
break;
|
case "checkbox":
|
value = false;
|
break;
|
case "date":
|
value = "";
|
break;
|
case "time":
|
value = "";
|
break;
|
case "ref-psn":
|
value = {};
|
break;
|
}
|
return value;
|
},
|
attrLabel(attr) {
|
if (attr.notempty || attr.def?.not_empty == 1)
|
return `${attr.name}(必填)`;
|
else return attr.name;
|
},
|
attrRequired(attr) {
|
if (attr.notempty || attr.def?.not_empty == 1) return true;
|
else return false;
|
},
|
toHexColor(num) {
|
return `#${parseInt(num).toString(16)}`;
|
},
|
async onChange(attr) {
|
if (!this.form[attr.attr]) return;
|
let action = attr.action;
|
if (!action) return;
|
if (action[0] != "{" && action[action.length - 1] != "}")
|
action = `{${action}}`;
|
let extInfo = {
|
...this.enviroment,
|
};
|
try {
|
await dataObjRunCustomEvent(
|
this.options.clsId,
|
action,
|
JSON.stringify(this.formAttrObj),
|
JSON.stringify(extInfo),
|
"",
|
""
|
)
|
} catch (ex) {
|
console.log("执行脚本失败", ex)
|
showModal(ex, '错误', false)
|
}
|
},
|
loadPlatform() {
|
this.isCanSelFile = true
|
this.isMobilePlatform = false
|
const app = getApp()
|
if (app.globalData.platform == "ios" || app.globalData.platform == "android") {
|
this.isMobilePlatform = true
|
}
|
// console.log("loadPlatform", app.globalData.osName)
|
if (app.globalData.osName == "ios") {
|
this.isCanSelFile = false
|
//#ifdef MP-WEIXIN
|
if (uni.canIUse('chooseMessageFile')) {
|
this.isCanSelFile = true
|
}
|
//#endif
|
}
|
},
|
clickShowAttach() {
|
this.showAttach = !this.showAttach
|
},
|
clickSelFile() {
|
|
let isCanMessageFile = false
|
let isCanLocalFile = true
|
const app = getApp()
|
|
if (app.globalData.osName == "ios") {
|
isCanLocalFile = false
|
}
|
//#ifdef MP-WEIXIN
|
if (app.globalData.qyWx.isWork) {
|
if (this.isMobilePlatform) {
|
if (uni.canIUse('chooseMessageFile')) {
|
isCanMessageFile = true
|
}
|
}
|
} else {
|
if (uni.canIUse('chooseMessageFile')) {
|
isCanMessageFile = true
|
}
|
}
|
//#endif
|
if (isCanLocalFile && isCanMessageFile) {
|
this.$refs.popupFileSel.open("bottom")
|
} else {
|
if (isCanLocalFile) {
|
uni.navigateTo({
|
url: `/pages/common/fileselect?uploadType=${this.fileUploadType}`
|
})
|
} else if (isCanMessageFile) {
|
this.clickSelMessageFile()
|
}
|
}
|
},
|
clickCamera() {
|
console.log("clickCamera")
|
var _this = this
|
let sizeType = ['original', 'compressed']
|
//#ifdef MP-DINGTALK
|
sizeType = ['compressed']
|
// #endif
|
|
uni.chooseImage({
|
count: 10,
|
sizeType: sizeType, //original 原图,compressed 压缩图,默认二者都有
|
sourceType: ['album', 'camera'], //album 从相册选图,camera 使用相机,默认二者都有。
|
success: (res) => {
|
console.log("clickCamera res", res)
|
let tempFiles = []
|
if (res.files) {
|
for (let i = 0; i < res.files.length; i++) {
|
let tmpFile = {
|
path: res.files[i].path,
|
size: 0
|
}
|
tmpFile.name = tmpFile.path
|
if (res.files[i].fileType)
|
tmpFile.name = tmpFile.path + "." + res.files[i].fileType
|
tempFiles.push(tmpFile)
|
}
|
} else if (res.tempFiles) {
|
for (let i = 0; i < res.tempFiles.length; i++) {
|
let tmpFile = {
|
path: res.tempFiles[i].path,
|
size: 0
|
}
|
tmpFile.name = tmpFile.path
|
tempFiles.push(tmpFile)
|
}
|
} else {
|
for (let i = 0; i < res.tempFilePaths.length; i++) {
|
tempFiles.push({
|
path: res.tempFilePaths[i],
|
name: res.tempFilePaths[i],
|
size: 0
|
})
|
}
|
}
|
_this.uploadAttachs(tempFiles);
|
|
},
|
fail: (err) => {
|
console.log('chooseImage fail', err)
|
if (_this.isMobilePlatform && err.errMsg.indexOf('cancel') < 0) {
|
uni.getSetting({
|
success: (res) => {
|
let authStatus = res.authSetting['scope.album'];
|
if (!authStatus) {
|
showModal("需要从您的相册获取图片,请在设置界面打开相关权限", "授权失败").then((
|
res) => {
|
if (res) {
|
uni.openSetting()
|
}
|
})
|
}
|
}
|
})
|
}
|
}
|
})
|
},
|
clickSelMessageFile() {
|
this.$refs.popupFileSel.close()
|
|
var _this = this
|
let app = getApp()
|
let isCanMessageFile = false
|
//#ifdef MP-WEIXIN
|
if (app.globalData.qyWx.isWork) {
|
if (this.isMobilePlatform) {
|
if (uni.canIUse('chooseMessageFile')) {
|
isCanMessageFile = true
|
}
|
}
|
} else {
|
if (uni.canIUse('chooseMessageFile')) {
|
isCanMessageFile = true
|
}
|
}
|
//#endif
|
if (isCanMessageFile) {
|
console.log("clickSelMessageFile canIUse")
|
if (app.globalData.qyWx.isWork) {
|
console.log("clickSelMessageFile wx.qy.checkSession")
|
wx.qy.checkSession({
|
success: function() {
|
// console.log('clickSelMessageFile checkSession success!')
|
wx.qy.chooseMessageFile({
|
count: 10,
|
type: "file",
|
success: (res) => {
|
// console.log("clickSelMessageFile chooseMessageFile success",res)
|
_this.uploadAttachs(res.tempFiles);
|
},
|
fail: (res) => {
|
console.log("clickSelMessageFile chooseMessageFile fail",
|
res)
|
},
|
})
|
},
|
fail: function() {
|
console.log('clickSelMessageFile checkSession fail!')
|
// session_key 已经失效,需要重新执行登录流程
|
loginWxQy().then((res) => {
|
wx.qy.chooseMessageFile({
|
count: 10,
|
type: "file",
|
success: (res) => {
|
console.log(
|
"clickSelMessageFile chooseMessageFile success",
|
res)
|
_this.uploadAttachs(res.tempFiles);
|
},
|
fail: (res) => {
|
console.log(
|
"clickSelMessageFile chooseMessageFile fail",
|
res)
|
},
|
})
|
}).catch((rej) => {
|
console.log('clickSelMessageFile loginWxQy failed!', rej)
|
showModal(rej, "提示", false)
|
})
|
}
|
})
|
} else {
|
uni.chooseMessageFile({
|
count: 10,
|
type: "all",
|
success: (res) => {
|
console.log("chooseMessageFile res", res)
|
_this.uploadAttachs(res.tempFiles);
|
}
|
})
|
}
|
} else {
|
console.log("clickSelMessageFile no canIUse")
|
//showModal("不支持从聊天会话中选择文件","提示",false)
|
let sizeType = ['original', 'compressed']
|
//#ifdef MP-DINGTALK
|
sizeType = ['compressed']
|
// #endif
|
uni.chooseImage({
|
count: 10,
|
sizeType: sizeType, //original 原图,compressed 压缩图,默认二者都有
|
sourceType: ['album', 'camera'], //album 从相册选图,camera 使用相机,默认二者都有。
|
success: (res) => {
|
console.log("clickCamera res", res)
|
let tempFiles = []
|
if (res.files) {
|
for (let i = 0; i < res.files.length; i++) {
|
let tmpFile = {
|
path: res.files[i].path,
|
size: 0
|
}
|
tmpFile.name = tmpFile.path.split('/').pop()
|
if (res.files[i].fileType)
|
tmpFile.name = tmpFile.path.split('/').pop() + "." + res.files[i]
|
.fileType
|
tempFiles.push(tmpFile)
|
}
|
} else if (res.tempFiles) {
|
for (let i = 0; i < res.tempFiles.length; i++) {
|
let tmpFile = {
|
path: res.tempFiles[i].path,
|
size: 0
|
}
|
tmpFile.name = tmpFile.path.split('/').pop()
|
tempFiles.push(tmpFile)
|
}
|
} else {
|
for (let i = 0; i < res.tempFilePaths.length; i++) {
|
tempFiles.push({
|
path: res.tempFilePaths[i],
|
name: res.tempFilePaths[i].split('/').pop(),
|
size: 0
|
})
|
|
}
|
}
|
|
_this.uploadAttachs(tempFiles);
|
|
},
|
fail: (err) => {
|
console.log('chooseImage fail', err)
|
if (_this.isMobilePlatform && err.errMsg.indexOf('cancel') < 0) {
|
uni.getSetting({
|
success: (res) => {
|
let authStatus = res.authSetting['scope.album'];
|
if (!authStatus) {
|
showModal("需要从您的相册获取图片,请在设置界面打开相关权限", "授权失败").then((
|
res) => {
|
if (res) {
|
uni.openSetting()
|
}
|
})
|
}
|
}
|
})
|
}
|
}
|
})
|
return;
|
}
|
|
},
|
clickSelLocalFile() {
|
console.log("clickSelLocalFile")
|
this.$refs.popupFileSel.close()
|
uni.navigateTo({
|
url: `/pages/common/fileselect?uploadType=${this.fileUploadType}`
|
})
|
},
|
uploadAttachs(files) {
|
console.log("uploadAttachs", files)
|
var _this = this
|
|
let fileTemps = []
|
var attachs = _this.attachList
|
if (files.length <= 10) {
|
fileTemps = files
|
} else {
|
for (let i = 0; i < 10; i++) {
|
fileTemps.push(files[i])
|
}
|
}
|
for (let i = 0; i < fileTemps.length; i++) {
|
let file = fileTemps[i];
|
file.isUploading = true
|
file.percent = 0
|
let aname = file.path
|
if (file.name)
|
aname = file.name
|
let aaa = aname.split('/');
|
if (aaa.length > 0) {
|
file.name = aaa[aaa.length - 1]
|
} else
|
file.name = aname
|
file.sizestr = TaskInit.fileUtils.getFileSizeStr(file.size)
|
file.color = TaskInit.fileUtils.getTypeBgColor(file.name)
|
file.isImg = false
|
file.isVideo = false
|
if (TaskInit.fileUtils.isPictureType(file.name)) //文档
|
{
|
file.isImg = true
|
} else if (TaskInit.fileUtils.isVideoType(file.name)) //文档
|
{
|
file.isVideo = true
|
}
|
attachs.push(file)
|
}
|
_this.setData({
|
attachList: attachs,
|
})
|
for (let i = 0; i < fileTemps.length; i++) {
|
let file = fileTemps[i];
|
if (_this.fileUploadType == 1) {
|
// #ifdef MP-WEIXIN
|
uni.getFileSystemManager().getFileInfo({
|
filePath: file.path,
|
digestAlgorithm: "md5",
|
success: (res) => {
|
console.log("uploadAttachs getFileInfo", res)
|
file.md5 = res.digest
|
_this.uploadAttachToMinio(file, file.isImg, file.isVideo)
|
},
|
fail: (res) => {
|
_this.setAttachFailed(file.path, res);
|
}
|
})
|
// #endif
|
// #ifndef MP-WEIXIN
|
uni.getFileInfo({
|
filePath: file.path,
|
digestAlgorithm: "md5",
|
success: (res) => {
|
file.md5 = res.digest
|
_this.uploadAttachToMinio(file, file.isImg, file.isVideo)
|
},
|
fail: (res) => {
|
_this.setAttachFailed(file.path, res);
|
}
|
})
|
// #endif
|
} else {
|
_this.uploadAttach(file, file.isImg, file.isVideo)
|
}
|
}
|
|
},
|
|
closeFileSelPopup() {
|
this.$refs.popupFileSel.close()
|
},
|
longpressPic(item, index) {
|
var _this = this
|
showModal("确定要删除附件吗?", "提醒").then((res) => {
|
if (res) {
|
let attachs = _this.attachList
|
if ( attachs[index].id)
|
this.delFileList.push(attachs[index].id)
|
attachs.splice(index, 1)
|
_this.setData({
|
attachList: attachs
|
})
|
|
}
|
})
|
},
|
onErrInfo(errMsg) {
|
console.log("onErrInfo", errMsg)
|
showToast(errMsg, 'none')
|
},
|
getBackUploadFile(data) {
|
var _this = this
|
let attachs = _this.attachList
|
for (let i = 0; i < data.length; i++) {
|
let file = data[i];
|
let isImg = false
|
let isVideo = false
|
//console.log('getBackUploadFile', file)
|
if (TaskInit.fileUtils.isPictureType(file.CN_S_FILE_NAME)) //文档
|
{
|
isImg = true
|
}
|
if (TaskInit.fileUtils.isVideoType(file.CN_S_FILE_NAME)) //文档
|
{
|
isVideo = true
|
}
|
let color = TaskInit.fileUtils.getTypeBgColor(file.CN_S_FILE_NAME)
|
let upfile = {
|
isUploading: false,
|
fileserver: file.CN_N_FILE_SERVER,
|
percent: 100,
|
fileId: file.CN_G_FILE_ID,
|
name: file.CN_S_FILE_NAME,
|
size: file.CN_N_FILE_SIZE,
|
fileMD5: file.CN_S_FILE_MD5 || "",
|
isImg: isImg,
|
isVideo: isVideo,
|
color: color,
|
sizestr: TaskInit.fileUtils.getFileSizeStr(file.CN_N_FILE_SIZE)
|
};
|
attachs.push(upfile)
|
|
}
|
_this.setData({
|
attachList: attachs
|
})
|
// console.log('getBackUploadFile', _this.attachList)
|
for (let i = 0; i < _this.attachList.length; i++) {
|
let file = _this.attachList[i];
|
if ((file.isImg || file.isVideo) && !file.path) {
|
getFileUrlS(file.fileId, file.fileserver, file.name).then((res) => {
|
console.log("getFileUrlS res:", res)
|
if (res.indexOf("file not exsits") < 0) {
|
const app = getApp()
|
if (res.indexOf("http://") < 0 && res.indexOf("https://") < 0)
|
res = app.globalData.basehttpurl + res
|
file.path = res
|
}
|
}).catch((rej) => {
|
console.log("getFileUrlS fail:", rej)
|
})
|
}
|
}
|
|
},
|
openAattachFile(item) {
|
var _this = this
|
if (!TaskInit.fileUtils.isCanPreviewType(item.name)) {
|
showToast("暂不支持此类型查看", "none")
|
return
|
}
|
|
if (TaskInit.fileUtils.isPictureType(item.name)) //文档
|
{
|
if (item.path) {
|
let arrImg = _this.getImgsUrl();
|
uni.previewImage({
|
current: item.path,
|
urls: arrImg,
|
})
|
return
|
}
|
_this.dldAndPreviewImg(item)
|
return
|
}
|
if (item.path) {
|
if (TaskInit.fileUtils.isDocumentType(item.name)) //文档
|
{
|
let aaa = item.name.toLowerCase().split('.');
|
let ftype = aaa.length > 0 ? aaa[aaa.length - 1] : aaa[0];
|
uni.openDocument({
|
fileType: ftype,
|
filePath: item.path,
|
success: function(res) {
|
console.log('打开文档成功');
|
},
|
fail: function() {
|
showToast("暂不支持此类型‘"+ftype+"’查看" ,"none",5000)
|
}
|
})
|
}
|
return
|
}
|
if (TaskInit.fileUtils.isVideoType(item.name)) //文档
|
{
|
getFileUrlS(item.fileId, item.fileserver, item.name).then((res) => {
|
console.log('getFileUrlS success:', res)
|
if (res.indexOf("file not exsits") < 0) {
|
const app = getApp()
|
if (res.indexOf("http://") < 0 && res.indexOf("https://") < 0)
|
res = app.globalData.basehttpurl + res
|
item.path = res
|
uni.navigateTo({
|
url: "/pages/common/videoPage?fileId=" + item.fileId + "&fileServer=" +
|
item.fileserver + "&name=" + item.name + "&url=" + encodeURIComponent(
|
item.path)
|
})
|
}
|
}).catch((rej) => {
|
console.log('getFileUrlS fail:', rej);
|
showModal(rej, '错误', false)
|
})
|
return
|
}
|
getFileUrlS(item.fileId, item.fileserver, item.name).then((res) => {
|
console.log('getFileUrlS success:', res)
|
if (res.indexOf("file not exsits") < 0) {
|
showLoading("正在下载,请稍后...")
|
const app = getApp()
|
if (res.indexOf("http://") < 0 && res.indexOf("https://") < 0)
|
res = app.globalData.basehttpurl + res
|
downloadTaskFile(item.name, res, function(docSuccess) {
|
|
hideLoading()
|
item.path = docSuccess.path
|
console.log('下载成功', docSuccess.path);
|
showLoading("下载成功,正在打开...")
|
let aaa = item.name.toLowerCase().split('.');
|
let ftype = aaa.length > 0 ? aaa[aaa.length - 1] : aaa[0];
|
uni.openDocument({
|
fileType: ftype,
|
filePath: docSuccess.path,
|
success: function(res) {
|
hideLoading()
|
console.log('打开文档成功');
|
},
|
fail: function() {
|
hideLoading()
|
showToast("暂不支持此类型‘"+ftype+"’查看" ,"none",5000)
|
}
|
})
|
}, function(docProgress, downloadTask) {
|
//下载进度
|
}, function(docFail) {
|
|
hideLoading()
|
showModal(docFail.errMsg, '错误', false)
|
})
|
} else {
|
showModal(res, '错误', false)
|
}
|
}).catch((rej) => {
|
console.log('getFileUrlS fail:', rej);
|
showModal(rej, '错误', false)
|
})
|
},
|
|
getImgsUrl() {
|
let imgs = []
|
this.attachList.forEach((item, index) => {
|
if (item.isImg && item.path) {
|
imgs.push(item.path)
|
}
|
})
|
return imgs
|
},
|
dldAndPreviewImg(item) {
|
var _this = this
|
getFileUrlS(item.fileId, item.fileserver, item.name).then((res) => {
|
console.log('getFileUrlS success:', res);
|
if (res.indexOf("file not exsits") < 0) {
|
const app = getApp()
|
if (res.indexOf("http://") < 0 && res.indexOf("https://") < 0)
|
res = app.globalData.basehttpurl + res
|
item.path = res
|
let arrImg = _this.getImgsUrl();
|
uni.previewImage({
|
current: item.path,
|
urls: arrImg,
|
})
|
} else {
|
showModal(res, '错误', false)
|
}
|
}).catch((rej) => {
|
console.log('getFileUrlS fail:', rej);
|
showModal(rej, '错误', false)
|
})
|
},
|
|
setAttachInfo(path, value) {
|
var _this = this
|
let attachs = [];
|
attachs = _this.attachList;
|
if (attachs.length == 0) {
|
return;
|
}
|
let curIndex = attachs.findIndex((item, index, arr) => {
|
return item.path == path;
|
})
|
if (curIndex == -1) {
|
return;
|
}
|
attachs[curIndex] = value;
|
_this.setData({
|
attachList: attachs
|
})
|
},
|
setAttachProgress(path, percent, uploadTask) {
|
var _this = this
|
if (percent < 1 || percent > 99) {
|
return;
|
}
|
let attachs = [];
|
attachs = _this.attachList;
|
if (attachs.length == 0) {
|
uploadTask.abort();
|
return;
|
}
|
let curIndex = attachs.findIndex((item, index, arr) => {
|
return item.path == path;
|
})
|
if (curIndex == -1) {
|
uploadTask.abort();
|
return;
|
}
|
let attachItem = attachs[curIndex]
|
attachItem.percent = percent
|
attachItem.isUploading = true
|
attachs[curIndex] = attachItem;
|
_this.setData({
|
attachList: attachs
|
})
|
},
|
setAttachFailed(path, errMsg) {
|
var _this = this
|
let attachs = [];
|
attachs = _this.attachList;
|
if (attachs.length == 0) {
|
return;
|
}
|
let curIndex = attachs.findIndex((item, index, arr) => {
|
return item.path == path;
|
})
|
if (curIndex == -1) {
|
return;
|
}
|
let attachItem = attachs[curIndex]
|
attachItem.isUploading = false
|
attachItem.errMsg = errMsg
|
attachs[curIndex] = attachItem;
|
_this.setData({
|
attachList: attachs
|
})
|
},
|
uploadAttachToMinio(file, isImg, isVideo) {
|
var _this = this
|
_this.setAttachFailed(file.path, "暂时不支持minio文件上传");
|
},
|
uploadAttach(file, isImg, isVideo) {
|
var _this = this
|
let color = TaskInit.fileUtils.getTypeBgColor(file.name)
|
uploadTaskFile(file, function(docSuc) {
|
let upfile = {
|
isUploading: false,
|
fileserver: docSuc.FileServer,
|
percent: 100,
|
fileId: docSuc.ID,
|
fileMD5: docSuc.FileMD5 || "",
|
name: docSuc.Name,
|
size: docSuc.Size,
|
path: docSuc.path,
|
|
isImg: isImg,
|
isVideo: isVideo,
|
color: color,
|
sizestr: TaskInit.fileUtils.getFileSizeStr(docSuc.Size)
|
};
|
_this.setAttachInfo(upfile.path, upfile);
|
// console.log("uploadAttach uploadTaskFile res", upfile);
|
},
|
function(docProgress, uploadTask) {
|
console.log("uploadAttach uploadTaskFile Process", docProgress);
|
_this.setAttachProgress(docProgress.path, docProgress.progress, uploadTask);
|
},
|
function(docFail) {
|
console.log("uploadAttach uploadTaskFile fail", docFail);
|
_this.setAttachFailed(docFail.path, docFail.errMsg);
|
})
|
},
|
getPostDataObjAttr() {
|
let obj_attr = {};
|
let form = this.formAttrObj;
|
this.showStyle.forEach((group) => {
|
group.attrs.forEach((attr) => {
|
if (attr.type == "ref-psn")
|
obj_attr[attr.attr] = `${(form[attr.attr].id || "").trim()};${(
|
form[attr.attr].name || ""
|
).trim()}`;
|
else if (attr.type == "date")
|
obj_attr[attr.attr] = form[attr.attr] ?
|
dayjs(form[attr.attr]).format("YYYY-MM-DD") :
|
"";
|
else
|
obj_attr[attr.attr] =
|
form[attr.attr] && typeof form[attr.attr] == "string" ?
|
form[attr.attr].trim() :
|
form[attr.attr];
|
});
|
});
|
// 脚本返回的属性列表
|
// Object.keys(this.otherAttrs).forEach((attr) => {
|
// if (!(attr in obj_attr)) obj_attr[attr] = this.otherAttrs[attr];
|
// });
|
|
// 新增模式中才需要使用默认值
|
// if (!this.editMode) {
|
// // 属性定义中的默认值
|
// this.attrList.forEach((group) => {
|
// group.attr_list.forEach((attr) => {
|
// if (!(attr.name in obj_attr) && typeof attr.def_value !== undefined)
|
// obj_attr[attr.name] = ['""', "''"].includes(attr.def_value) ?
|
// "" :
|
// attr.def_value;
|
// });
|
// });
|
// }
|
// // 数据指定为文件时,要附加文件信息
|
// if (this.clsInfo.has_file == 1) {
|
// let {
|
// id,
|
// name,
|
// size,
|
// md5
|
// } = this.refFile.file;
|
// obj_attr["G_FILE_ID"] = id;
|
// obj_attr["S_FILE_NAME"] = name;
|
// obj_attr["S_FILE_SERVER"] = window.file_svr.files_flag;
|
// obj_attr["S_FILE_TYPE"] = name
|
// .slice(name.lastIndexOf("."))
|
// .toLowerCase();
|
// obj_attr["N_FILE_SIZE"] = size;
|
// obj_attr["S_FILE_MD5"] = md5;
|
// }
|
|
return obj_attr;
|
},
|
|
async submitForm() {
|
console.log("submitForm")
|
var _this = this
|
|
try {
|
|
const attrs = _this.getPostDataObjAttr()
|
const req = Object.keys(attrs).map((a) => {
|
return {
|
name: a,
|
value: attrs[a] || ""
|
}
|
})
|
const upfile = []
|
if (this.options.objId) {
|
this.attachList.forEach((file) => {
|
|
if (file.fileId && !file.id) {
|
|
const item = {
|
FileID: file.fileId.includes("{") ? file.fileId : `{${file.fileId}}`,
|
FileSize: file.size,
|
FileName: file.name,
|
FileMD5: file.fileMD5
|
}
|
upfile.push(item)
|
}
|
|
})
|
const res = await updateClassAttr(this.options.clsId,this.options.objId ,req, upfile, this.delFileList)
|
|
} else {
|
this.attachList.forEach((file) => {
|
if (file.fileId) {
|
const item = {
|
FileID: file.fileId.includes("{") ? file.fileId : `{${file.fileId}}`,
|
FileSize: file.size,
|
FileName: file.name,
|
FileMD5: file.fileMD5
|
}
|
upfile.push(item)
|
}
|
|
})
|
|
const res = await addClassAttr(this.options.clsId, req, upfile, this.extInfo)
|
}
|
|
uni.$emit('dataObjChange', this.options.appId)
|
uni.navigateBack();
|
|
} catch (ex) {
|
let tip = typeof ex == "string" ? ex : ex.message;
|
console.log(`添加数据失败`, ex);
|
showModal(tip, "出错", false, false)
|
}
|
},
|
showError(ex) {
|
let tip = typeof ex == 'string' ? ex : typeof ex.err_msg == 'string' ? ex.err_msg : typeof ex.errMsg ==
|
'string' ? ex.errMsg : ""
|
showModal(tip, "提示", false)
|
},
|
|
},
|
onLoad(option) {
|
|
this.options = option
|
// #ifdef MP-DINGTALK
|
|
my.setNavigationBar({
|
backgroundColor: "#007AFF",
|
frontColor: "#ffffff"
|
})
|
// #endif
|
this.globalAttr = option.globalAttr || ""
|
uni.setNavigationBarTitle({
|
title: this.options.title || "新增"
|
})
|
this.loadPlatform()
|
this.loadData()
|
getUploadType().then((res) => {
|
this.setData({
|
fileUploadType: res
|
})
|
console.log("getUploadType:", res)
|
}).catch((rej) => {
|
console.log("getUploadType fail:", rej)
|
})
|
|
},
|
}
|
</script>
|
<style lang="scss">
|
.view-data-new-dataobj {
|
background-color: #e5eaee;
|
width: 750rpx;
|
height: 100vh;
|
display: flex;
|
flex-direction: column;
|
|
.uni-forms {
|
padding: 5px;
|
overflow: auto;
|
flex: 1;
|
}
|
|
.uni-collapse {
|
background-color: #e5eaee;
|
|
.uni-collapse-item {
|
border-radius: 8px;
|
background-color: #fff;
|
margin: 5px;
|
padding-bottom: 5px;
|
|
}
|
|
}
|
|
.uni-group-item {
|
border-radius: 8px;
|
background-color: #fff;
|
margin: 5px;
|
padding-bottom: 5px;
|
|
}
|
|
.uni-select {
|
border: 0;
|
}
|
|
.uni-panel-title {
|
display: flex;
|
width: calc(100% - 10rpx);
|
flex-direction: row;
|
}
|
|
.uni-title-icon {
|
background-color: #ffdd00;
|
border-radius: 50%;
|
width: 36px;
|
height: 36px;
|
margin: 5px;
|
margin-right: 12px;
|
display: inline-block;
|
vertical-align: middle;
|
text-align: center;
|
line-height: 40px;
|
|
.uni-icon {
|
color: #fff;
|
font-size: 20px
|
}
|
|
}
|
|
.uni-title-text {
|
flex: 1;
|
font-weight: 600;
|
line-height: 45px;
|
}
|
|
.uni-panel-icon-btn {
|
font-size: 18px;
|
padding: 8px;
|
margin-top: 5px;
|
// height: 36px;
|
// width: 36px;
|
|
}
|
|
.uni-panel-text {
|
flex: 1;
|
color: #000000;
|
font-weight: normal;
|
}
|
|
.uni-head-style {
|
display: flex;
|
flex-direction: column;
|
width: calc(100% - 30rpx);
|
padding: 15rpx;
|
}
|
|
.uni-head-style input {
|
width: calc(100% - 20rpx);
|
height: 52rpx;
|
line-height: 34rpx;
|
background: #FFF;
|
border-radius: 0 !important;
|
color: #2d8cf0;
|
padding: 10rpx 10rpx 12rpx;
|
font-size: 34rpx;
|
font-family: inherit;
|
box-shadow: none !important;
|
transition-duration: 0.1s;
|
margin-top: 4rpx;
|
}
|
|
.input-disabled {
|
background-color: #f3f3f3 !important;
|
}
|
|
.uni-hidden {
|
display: none;
|
}
|
|
.input-wrapper {
|
border: 1px solid #d5d5d5;
|
width: 100%;
|
line-height: 22rpx;
|
}
|
|
.uni-panel-upfile {
|
display: flex;
|
flex-wrap: wrap;
|
flex-direction: row !important;
|
|
.uni-panel-upfile-item {
|
display: flex;
|
position: relative;
|
margin: 2rpx;
|
height: 200rpx;
|
width: 30%;
|
flex-direction: column;
|
padding: 4px;
|
justify-content: center;
|
align-items: center;
|
}
|
|
.uni-panel-upfile-img {
|
display: flex;
|
height: 100%;
|
width: 100%;
|
}
|
|
.uni-panel-video-playIcon {
|
display: flex;
|
flex: 1;
|
width: 50%;
|
}
|
|
.uni-panel-upfile-item-name {
|
display: flex;
|
flex: 1;
|
color: #fff;
|
width: 100%;
|
word-wrap: break-word;
|
word-break: break-all;
|
font-size: 14px;
|
max-height: calc(200rpx - 20px);
|
text-overflow: ellipsis;
|
overflow: hidden;
|
-webkit-line-clamp: 4; //表明是2行文本显示省略号,换成3则表明是3行文本显示省略号
|
-webkit-box-orient: vertical;
|
}
|
|
.uni-panel-upfile-item-size {
|
display: flex;
|
height: 18px;
|
color: #fff;
|
font-size: 14px;
|
text-align: left;
|
}
|
|
.uni-panel-icon {
|
font-weight: normal;
|
font-size: 16px;
|
padding: 4px;
|
}
|
|
|
|
}
|
|
.uni-panel-bottom-button {
|
display: flex;
|
justify-content: center;
|
width: 100%;
|
font-size: 17px !important;
|
margin-top: 8px;
|
margin-bottom: 8px;
|
border-radius: 0px;
|
}
|
|
.uni-panel-button {
|
flex: 1;
|
border-radius: 12px;
|
margin: 5px 12px 16px;
|
background-color: #00aaff;
|
color: #fff;
|
}
|
|
.popup-content {
|
display: flex;
|
justify-content: center;
|
flex-direction: column;
|
background-color: transparent;
|
}
|
.popup-content_menu-item {
|
display: flex;
|
background-color: transparent;
|
justify-content: center;
|
padding: 12px;
|
font-size: 16px;
|
}
|
|
|
|
}
|
</style>
|