gree_leran/unpackage/dist/dev/mp-weixin/components/UpdateUserBox/UpdateUserBox.js

125 lines
3.8 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const apis_user = require("../../apis/user.js");
const utils_http = require("../../utils/http.js");
require("../../utils/Auth.js");
if (!Array) {
const _easycom_up_upload2 = common_vendor.resolveComponent("up-upload");
const _easycom_InputBox2 = common_vendor.resolveComponent("InputBox");
(_easycom_up_upload2 + _easycom_InputBox2)();
}
const _easycom_up_upload = () => "../../node-modules/uview-plus/components/u-upload/u-upload.js";
const _easycom_InputBox = () => "../InputBox/InputBox.js";
if (!Math) {
(_easycom_up_upload + _easycom_InputBox)();
}
const _sfc_main = {
__name: "UpdateUserBox",
emits: ["updata"],
setup(__props, { emit: __emit }) {
const emit = __emit;
const fileList1 = common_vendor.ref([]);
const inputVisible = common_vendor.ref(false);
const open = () => {
inputVisible.value = true;
};
const blurCom = () => {
inputVisible.value = false;
};
const submitNote = async (name) => {
blurCom();
common_vendor.index.showLoading({
title: "正在修改..."
});
let res = await apis_user.updateUserName(name);
try {
if (res.code == 200) {
common_vendor.index.showToast({
icon: "none",
title: "修改成功"
});
emit("updata");
} else {
common_vendor.index.showToast({
icon: "none",
title: "修改失败,请检查网络"
});
emit("updata");
}
} catch (error) {
common_vendor.index.showToast({
icon: "none",
title: "修改失败,请检查网络"
});
emit("updata");
} finally {
common_vendor.index.hideLoading();
}
};
const afterRead = async (event) => {
let lists = [].concat(event.file);
for (let item of lists) {
try {
common_vendor.index.showLoading({
title: "正在修改..."
});
let res = await utils_http.uploadFile(item.url);
res = JSON.parse(res);
let jg = await apis_user.updateUserImage(res.url);
if (jg.code == 200) {
common_vendor.index.showToast({
icon: "none",
title: "修改成功"
});
emit("updata");
} else {
common_vendor.index.showToast({
icon: "none",
title: "修改失败,请检查网络"
});
emit("updata");
fileList1.value = [];
}
} catch (error) {
common_vendor.index.showToast({
icon: "none",
title: "修改失败,请检查网络"
});
emit("updata");
fileList1.value = [];
} finally {
common_vendor.index.hideLoading();
}
}
};
const deletePic = (event) => {
fileList1.value.splice(event.index, 1);
};
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.o(afterRead),
b: common_vendor.o(deletePic),
c: common_vendor.p({
fileList: fileList1.value,
name: "1",
multiple: true,
maxCount: 1,
previewFullImage: true,
width: "400rpx",
height: "300rpx"
}),
d: common_vendor.o(open),
e: inputVisible.value
}, inputVisible.value ? {
f: common_vendor.o(submitNote),
g: common_vendor.o(blurCom),
h: common_vendor.p({
text: "修改"
})
} : {});
};
}
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-73f407f3"], ["__file", "D:/uniapp1/gree_leran/components/UpdateUserBox/UpdateUserBox.vue"]]);
wx.createComponent(Component);