// 当页面渲染完毕后马上调用下面的函数,这个函数是在当前页面 – 设置 – 生命周期 – 页面加载完成时中被关联的。
export function didMount() {
console.log(「页面 JS」:当前页面地址 ${location.href}
);
// console.log(「页面 JS」:当前页面 id 参数为 ${this.state.urlParams.id}
);
// 更多 this 相关 API 请参考:https://www.yuque.com/yida/support/ocmxyv#OCEXd
// document.title = window.loginUser.userName + ‘ | 宜搭’;
this.utils.loadScript(‘https://g.alicdn.com/code/lib/qrcodejs/1.0.0/qrcode.min.js’);
this.queryData()
}
export function queryData(){
this.dataSourceMap.getDatas.load({
formUuid: “FORM-IY966L71V86F7B0MCQ2VD4F8TYGP3J964LWNLB”,
}).then(res => {
if (res.data) {
const tableList = res.data.map(item => {
return {
“id”: item.formInstId,
“name”: item.formData.textField_lnwl4g9m,
“type”: item.formData.textField_lnwl4g9n,
“remake”: item.formData.textareaField_lnwl4g9p,
“praise”: item.formData.numberField_lnwl4g9t,
“share”: item.formData.numberField_lnwl4g9r,
}
})
// const tableList = []
// res.data.forEach(item => {
// const tableData = {
// “id”: item.formInstId,
// “name”: item.formData.textField_lnwl4g9m,
// “type”: item.formData.textField_lnwl4g9n,
// “remake”: item.formData.textareaField_lnwl4g9p,
// “praise”: item.formData.numberField_lnwl4g9t,
// “share”: item.formData.numberField_lnwl4g9r,
// }
// tableList.push(tableData)
// })
const dataSource = {
currentPage: 1,
totalCount: res.totalCount,
data: tableList,
}
console.log(dataSource)
this.$('tablePc_lnwl8e68').set("data", dataSource)
}
})
}
export function onAddItemClick() {
this.state.mode = “add”
this.$(‘dialog_lnwp3m47’).show()
}
/**
-
dialog onOk
*/
export function onOk() {this.dataSourceMap.saveData.load({
formUuid: "FORM-IY966L71V86F7B0MCQ2VD4F8TYGP3J964LWNLB", appType: "APP_JWE2RULYEKZFNB23S8II", formDataJson: JSON.stringify({ "textField_lnwl4g9m": this.$('textField_lnwp3m49').get('value'), "textField_lnwl4g9n": this.$('selectField_lnl47ou2').get('value'), "textareaField_lnwl4g9p": this.$('textField_lnwp3m4d').get('value'), "numberField_lnwl4g9t": this.$('numberField_lnwp3m4f').get('value'), "numberField_lnwl4g9r": this.$('numberField_lnwp3m4h').get('value'), })
}).then(res => {
this.$('dialog_lnwp3m47').hide() this.queryData()
})
}
export function onActionClick(rowData) {
this.utils.dialog({
method: ‘confirm’, // ‘alert’, ‘confirm’, ‘show’
title: ‘温馨提示’,
content: ‘数据删除后无法恢复,是否确认’, // 如需换行可传入 HTML/JSX 来实现
onOk: () => {
this.dataSourceMap.deleteData.load({
formInstId: rowData.id
}).then(res => {
console.log(res)
this.queryData()
})
},
onCancel: () => {},
});
}
export function onUpdateItemClick() {
// this.state.selectedArr.forEach(item => {
// const params = {
// formInstId: item,
// updateFormDataJson: JSON.stringify({
// “textField_lnwl4g9n”: this.$(‘selectField_lnwtsr80’).get(“value”)
// })
// }
// this.dataSourceMap.updateData.load(params).then(res => { //调用接口
// })
// })
// this.queryData();
let promiseArr = []
this.state.selectedArr.forEach(item => {
const params = {
formInstId: item,
updateFormDataJson: JSON.stringify({
“textField_lnwl4g9n”: this.$(‘selectField_lnwtsr80’).get(“value”)
})
}
const promise = new Promise((pres, rej) => {
this.dataSourceMap.updateData.load(params).then(res => { //调用接口
pres() //单个接口执行完毕
})
})
promiseArr.push(promise)
})
//栅栏函数
Promise.all(promiseArr).then((result) => {
this.utils.toast({
title: ‘Update Success!’,
});
this.queryData();
})
}
export function onSelectChange(selectedRowKeys, records) {
console.log(“AAA”,selectedRowKeys, records);
this.state.selectedArr = selectedRowKeys
}
let updateID;
//点击修改
export function onUpdateClick(rowData) {
this.state.mode = “update”
updateID = rowData.id
console.log(rowData);
this.$(‘textField_lnwp3m49’).set(“value”,rowData.name)
this.$(‘selectField_lnl47ou2’).set(“value”, rowData.type)
this.$(‘textField_lnwp3m4d’).set(“value”, rowData.remake)
this.$(‘numberField_lnwp3m4f’).set(“value”, rowData.share)
this.$(‘numberField_lnwp3m4h’).set(“value”, rowData.praise)
this.$(‘dialog_lnwp3m47’).show()
}
export function onQRCodeClick(rowData) {
const text = “https://zjyc.aliwork.com/o/hzyc/project” + “?pro=” + rowData.name
this.$(‘textField_lny1z2x4’).set(“value”, text)
this.$(‘dialog_lny0yafp’).show()
if (!document.getElementById(‘qrcodeRootDom’)) {
// 若没有 qrcodeRootDom 则创建一个
const qrcodeRoot = document.createElement(‘div’);
qrcodeRoot.setAttribute(‘id’, ‘qrcodeRootDom’);
qrcodeRoot.style.display = ‘none’;
window.document.body.appendChild(qrcodeRoot);
};
document.getElementById(‘qrcodeRootDom’).innerHTML = ”; // 清空内容
const qrcode = new QRCode(document.getElementById(‘qrcodeRootDom’), {
text: encodeURI(text),// 二维码内容
width: 220, // 二维码宽度
height: 220, // 二维码高度
colorDark: ‘#000000’,
colorLight: ‘#ffffff’,
correctLevel: QRCode.CorrectLevel.H
});
const canvas = qrcode._el.querySelector(‘canvas’); // 获取生成二维码中的canvas,并将canvas转换成base64
const qrcodeUrl = canvas.toDataURL(‘image/png’); // 获取到生成的二维码的图片链接
this.$(‘image_lny0yafq’).set(“src”, qrcodeUrl)
return qrcodeUrl;