| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const api_studentProject = require("../../api/studentProject.js");
- const _sfc_main = {
- setup() {
- const form = common_vendor.ref({
- // Note: form fields map to MainStudentProjectBo fields
- name: "",
- role: "",
- startTime: "",
- endTime: "",
- desc: "",
- performance: "",
- link: ""
- });
- const isComplete = common_vendor.computed(() => {
- return !!(form.value.name && form.value.role && form.value.startTime && form.value.desc);
- });
- const editIndex = common_vendor.ref(-1);
- const isEdit = common_vendor.computed(() => editIndex.value !== -1);
- common_vendor.onLoad((options) => {
- if (options && options.index !== void 0) {
- editIndex.value = parseInt(options.index);
- const data = common_vendor.index.getStorageSync("edit_data_project");
- if (data) {
- form.value = {
- id: data.id,
- name: data.projectName || data.name || "",
- role: data.role || "",
- startTime: data.startTime || "",
- endTime: data.endTime || "",
- desc: data.description || data.desc || "",
- performance: data.achievement || data.performance || "",
- link: data.link || ""
- };
- }
- }
- common_vendor.index.setNavigationBarTitle({ title: isEdit.value ? "修改项目经历" : "添加项目经历" });
- });
- const goBack = () => {
- common_vendor.index.navigateBack();
- };
- const yearOptions = [];
- const monthOptions = [];
- const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
- for (let i = 1990; i <= currentYear + 10; i++) {
- yearOptions.push(i + "年");
- }
- for (let i = 1; i <= 12; i++) {
- monthOptions.push((i < 10 ? "0" + i : i) + "月");
- }
- const showDatePicker = common_vendor.ref(false);
- const datePickerType = common_vendor.ref("start");
- const datePickerValue = common_vendor.ref([currentYear - 1990, 0]);
- const tempStartTime = common_vendor.ref("");
- const tempEndTime = common_vendor.ref("");
- const switchDateTab = (type) => {
- datePickerType.value = type;
- const target = type === "start" ? tempStartTime.value : tempEndTime.value;
- if (target && target !== "至今") {
- const parts = target.split(".");
- let yIdx = yearOptions.indexOf(parts[0] + "年");
- let mIdx = monthOptions.indexOf(parts[1] + "月");
- if (yIdx === -1)
- yIdx = currentYear - 1990;
- if (mIdx === -1)
- mIdx = 0;
- datePickerValue.value = [yIdx, mIdx];
- } else {
- datePickerValue.value = [currentYear - 1990, 0];
- if (type === "start" && !tempStartTime.value) {
- tempStartTime.value = `${currentYear}.01`;
- }
- }
- };
- const openDatePicker = (type) => {
- tempStartTime.value = form.value.startTime;
- tempEndTime.value = form.value.endTime;
- showDatePicker.value = true;
- switchDateTab(type);
- };
- const closeDatePicker = () => {
- showDatePicker.value = false;
- };
- const onDatePickerChange = (e) => {
- datePickerValue.value = e.detail.value;
- const yIdx = datePickerValue.value[0] !== void 0 ? datePickerValue.value[0] : currentYear - 1990;
- const mIdx = datePickerValue.value[1] !== void 0 ? datePickerValue.value[1] : 0;
- const yVal = yearOptions[yIdx].replace("年", "");
- const mVal = monthOptions[mIdx].replace("月", "");
- const formatted = `${yVal}.${mVal}`;
- if (datePickerType.value === "start") {
- tempStartTime.value = formatted;
- } else {
- tempEndTime.value = formatted;
- }
- };
- const confirmDatePicker = () => {
- form.value.startTime = tempStartTime.value;
- form.value.endTime = tempEndTime.value;
- showDatePicker.value = false;
- };
- const saveForm = async () => {
- if (!isComplete.value)
- return;
- common_vendor.index.showLoading({ title: "保存中..." });
- try {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- const studentId = userInfo ? userInfo.studentId : null;
- if (!studentId) {
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({ title: "登录失效,请重新登录", icon: "none" });
- return;
- }
- const reqData = {
- studentId,
- projectName: form.value.name,
- role: form.value.role,
- startTime: form.value.startTime,
- endTime: form.value.endTime,
- description: form.value.desc,
- achievement: form.value.performance,
- link: form.value.link
- };
- if (isEdit.value) {
- reqData.id = form.value.id;
- const res = await api_studentProject.updateStudentProject(reqData);
- common_vendor.index.hideLoading();
- if (res.code === 200) {
- common_vendor.index.showToast({ title: "修改成功", icon: "success" });
- common_vendor.index.removeStorageSync("edit_data_project");
- setTimeout(() => {
- common_vendor.index.$emit("refresh_experience");
- common_vendor.index.navigateBack();
- }, 1e3);
- } else {
- common_vendor.index.showToast({ title: res.msg || "修改失败", icon: "none" });
- }
- } else {
- const res = await api_studentProject.addStudentProject(reqData);
- common_vendor.index.hideLoading();
- if (res.code === 200) {
- common_vendor.index.showToast({ title: "添加成功", icon: "success" });
- setTimeout(() => {
- common_vendor.index.$emit("refresh_experience");
- common_vendor.index.navigateBack();
- }, 1e3);
- } else {
- common_vendor.index.showToast({ title: res.msg || "添加失败", icon: "none" });
- }
- }
- } catch (error) {
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({ title: "网络异常,保存失败", icon: "none" });
- common_vendor.index.__f__("error", "at pages/experience/add-project.js:175", error);
- }
- };
- return {
- form,
- isComplete,
- isEdit,
- goBack,
- showDatePicker,
- datePickerType,
- datePickerValue,
- yearOptions,
- monthOptions,
- tempStartTime,
- tempEndTime,
- openDatePicker,
- closeDatePicker,
- switchDateTab,
- onDatePickerChange,
- confirmDatePicker,
- saveForm
- };
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: !_ctx.form.name
- }, !_ctx.form.name ? {} : {}, {
- b: _ctx.form.name,
- c: common_vendor.o(($event) => _ctx.form.name = $event.detail.value),
- d: !_ctx.form.role
- }, !_ctx.form.role ? {} : {}, {
- e: _ctx.form.role,
- f: common_vendor.o(($event) => _ctx.form.role = $event.detail.value),
- g: !_ctx.form.startTime
- }, !_ctx.form.startTime ? {} : {}, {
- h: common_vendor.t(_ctx.form.startTime || "开始时间"),
- i: common_vendor.n(!_ctx.form.startTime ? "is-empty" : ""),
- j: common_vendor.o(($event) => _ctx.openDatePicker("start")),
- k: common_vendor.t(_ctx.form.endTime || "至今"),
- l: common_vendor.n(!_ctx.form.endTime ? "is-empty" : ""),
- m: common_vendor.o(($event) => _ctx.openDatePicker("end")),
- n: !_ctx.form.desc
- }, !_ctx.form.desc ? {} : {}, {
- o: _ctx.form.desc,
- p: common_vendor.o(($event) => _ctx.form.desc = $event.detail.value),
- q: _ctx.form.performance,
- r: common_vendor.o(($event) => _ctx.form.performance = $event.detail.value),
- s: _ctx.form.link,
- t: common_vendor.o(($event) => _ctx.form.link = $event.detail.value),
- v: _ctx.isEdit
- }, _ctx.isEdit ? {} : {}, {
- w: !_ctx.isComplete ? 1 : "",
- x: common_vendor.o((...args) => _ctx.saveForm && _ctx.saveForm(...args)),
- y: _ctx.showDatePicker
- }, _ctx.showDatePicker ? {
- z: common_vendor.o((...args) => _ctx.closeDatePicker && _ctx.closeDatePicker(...args)),
- A: common_vendor.t(_ctx.tempStartTime || "开始时间"),
- B: common_vendor.n(_ctx.datePickerType === "start" ? "active" : ""),
- C: common_vendor.o(($event) => _ctx.switchDateTab("start")),
- D: common_vendor.t(_ctx.tempEndTime || "至今"),
- E: common_vendor.n(_ctx.datePickerType === "end" ? "active" : ""),
- F: common_vendor.o(($event) => _ctx.switchDateTab("end")),
- G: common_vendor.f(_ctx.yearOptions, (item, index, i0) => {
- return {
- a: common_vendor.t(item),
- b: index
- };
- }),
- H: common_vendor.f(_ctx.monthOptions, (item, index, i0) => {
- return {
- a: common_vendor.t(item),
- b: index
- };
- }),
- I: _ctx.datePickerValue,
- J: common_vendor.o((...args) => _ctx.onDatePickerChange && _ctx.onDatePickerChange(...args)),
- K: common_vendor.o((...args) => _ctx.confirmDatePicker && _ctx.confirmDatePicker(...args)),
- L: common_vendor.o(() => {
- })
- } : {});
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2351dbd1"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/experience/add-project.js.map
|