Browse Source

修改 bug

master
王泽彦 8 months ago
parent
commit
d2981c803d
  1. 17
      niucloud/app/api/route/route.php
  2. 12
      uniapp/common/axios.js
  3. 2
      uniapp/common/config.js
  4. 142
      uniapp/pages/common/personnel/add_personnel.vue

17
niucloud/app/api/route/route.php

@ -42,6 +42,12 @@ Route::group(function () {
Route::post('send/mobile/:type', 'login.Login/sendMobileCode');
Route::get('testfun1', 'sys.Index/testfun1');
//员工端-上传图片
Route::post('uploadImage', 'upload.Upload/image');
//员工端-添加新员工信息
Route::post('personnel/add', 'apiController.Personnel/add');
});
/**
@ -195,15 +201,14 @@ Route::group(function () {
Route::get('common/getClassAll', 'apiController.Common/getClassAll');
//公共端-获取支付类型字典(员工端)
Route::get('common/getPaymentTypes', 'apiController.Common/getPaymentTypes');
//员工端-获取审批配置列表
Route::get('personnel/approval-configs', 'apiController.Personnel/getApprovalConfigs');
})->middleware(ApiChannel::class)
->middleware(ApiLog::class);
//需要token验证的
Route::group(function () {
//员工端-上传图片
Route::post('uploadImage', 'upload.Upload/image');
//员工端-上传文档
Route::post('uploadDocument', 'upload.Upload/document');
//员工端详情
@ -220,10 +225,8 @@ Route::group(function () {
Route::get('personnel/getPersonnelAll', 'apiController.Personnel/getPersonnelAll');
//员工端-获取教练数据列表
Route::get('personnel/getCoachList', 'apiController.Personnel/getCoachList');
//员工端-添加新员工信息
Route::post('personnel/add', 'apiController.Personnel/add');
//员工端-获取审批配置列表
Route::get('personnel/approval-configs', 'apiController.Personnel/getApprovalConfigs');
//员工端统计(销售)-获取销售首页数据统计
Route::get('statistics/marketHome', 'apiController.Statistics/marketHome');

12
uniapp/common/axios.js

@ -61,7 +61,7 @@ const responseInterceptor = (response) => {
uni.setStorageSync("expires_time", data.data.expires_time);
}
}
return data;
// 成功情况直接返回数据
} else if (data.code === 401) {
console.error('401错误 - 未授权');
// 未授权或token过期,清除所有用户缓存信息
@ -98,12 +98,14 @@ const responseInterceptor = (response) => {
}, 1500);
throw new Error(data.msg || '未授权');
} else {
uni.showToast({
title: data.msg || '请求失败',
icon: 'none'
});
// 不要在这里显示toast,让业务层自己处理错误信息
// uni.showToast({
// title: data.msg || '请求失败',
// icon: 'none'
// });
}
}
// 始终返回数据,让业务层判断成功失败
return data;
}
};

2
uniapp/common/config.js

@ -1,5 +1,5 @@
// 环境变量配置
const env = 'development'
const env = 'prod'
// const env = 'prod'
const isMockEnabled = false // 默认禁用Mock优先模式,仅作为回退
const isDebug = false // 默认启用调试模式

142
uniapp/pages/common/personnel/add_personnel.vue

@ -265,7 +265,7 @@
<view class="approval-info">
<view class="info-item">
<text class="info-label">审批流程</text>
<text class="info-value">{{approvalData.selectedConfig ? approvalData.selectedConfig.config_name : '新入职申请'}}</text>
<text class="info-value">{{currentApprovalConfigName}}</text>
</view>
<view class="info-note">
<text>提交后将进入审批流程请等待审批完成</text>
@ -380,6 +380,20 @@ export default {
maritalStatusOptions: ['未婚', '已婚', '离异', '丧偶']
}
},
computed: {
//
currentApprovalConfigName() {
if (this.approvalData.selectedConfig && this.approvalData.selectedConfig.config_name) {
return this.approvalData.selectedConfig.config_name
}
return '新入职申请'
},
//
shouldShowApprovalError() {
return this.currentStep === 3 && this.approvalData.useApproval &&
!this.approvalData.selectedConfig && this.approvalConfigs.length === 0
}
},
onLoad() {
//
const today = new Date()
@ -544,9 +558,26 @@ export default {
this.approvalData.selectedConfig = this.approvalConfigs[0]
this.approvalData.selectedIndex = 0
}
console.log('审批配置加载成功:', this.approvalConfigs)
} else {
console.error('审批配置加载失败:', response.data.msg)
//
this.approvalData.selectedConfig = {
id: 0,
config_name: '新入职申请',
description: '新入职申请',
business_type: 'personnel_add'
}
}
} catch (error) {
console.error('加载审批配置失败:', error)
//
this.approvalData.selectedConfig = {
id: 0,
config_name: '新入职申请',
description: '新入职申请',
business_type: 'personnel_add'
}
}
},
@ -574,28 +605,103 @@ export default {
return
}
//
console.log('开始提交表单...')
console.log('当前审批配置:', this.approvalData.selectedConfig)
// 使
if (this.approvalData.useApproval && !this.approvalData.selectedConfig) {
uni.showToast({
title: '审批流程配置加载失败,请重试',
icon: 'none'
})
return
console.log('审批配置未加载,尝试重新加载...')
await this.loadApprovalConfigs()
// 使
if (!this.approvalData.selectedConfig) {
this.approvalData.selectedConfig = {
id: 0,
config_name: '新入职申请',
description: '新入职申请',
business_type: 'personnel_add'
}
console.log('使用默认审批配置:', this.approvalData.selectedConfig)
}
}
this.submitting = true
try {
// null
const processField = (value, allowEmpty = true) => {
if (value === null || value === undefined) {
return null
}
if (typeof value === 'string') {
const trimmed = value.trim()
return trimmed === '' ? (allowEmpty ? '' : null) : trimmed
}
return value
}
// null
const processDateField = (dateValue) => {
return processField(dateValue, false) //
}
// null
const processNumberField = (numberValue) => {
if (numberValue === null || numberValue === undefined || numberValue === '') {
return null
}
return numberValue
}
const submitData = {
...this.formData,
...this.detailData,
//
name: this.formData.name,
gender: this.formData.gender,
phone: this.formData.phone,
account_type: this.formData.account_type,
//
head_img: processField(this.formData.head_img),
birthday: processDateField(this.formData.birthday),
email: processField(this.formData.email),
wx: processField(this.formData.wx),
join_time: processDateField(this.formData.join_time),
//
ethnicity: processField(this.detailData.ethnicity),
age: processNumberField(this.detailData.age),
politics: processField(this.detailData.politics),
university: processField(this.detailData.university),
education: processField(this.detailData.education),
major: processField(this.detailData.major),
graduation_date: processDateField(this.detailData.graduation_date),
native_place: processField(this.detailData.native_place),
household_place: processField(this.detailData.household_place),
household_type: processField(this.detailData.household_type),
household_address: processField(this.detailData.household_address),
current_address: processField(this.detailData.current_address),
emergency_contact: processField(this.detailData.emergency_contact),
emergency_phone: processField(this.detailData.emergency_phone),
marital_status: processField(this.detailData.marital_status),
bank_card: processField(this.detailData.bank_card),
bank_name: processField(this.detailData.bank_name),
remark: processField(this.detailData.remark),
//
use_approval: this.approvalData.useApproval,
approval_config_id: this.approvalData.selectedConfig ? this.approvalData.selectedConfig.id : 0
}
console.log('提交数据:', submitData)
const response = await apiRoute.post('personnel/add', submitData)
if (response.data.code === 1) {
console.log('提交响应:', response)
console.log('响应数据结构:', response.data || response)
console.log('响应码:', response.code, '类型:', typeof response.code)
if (response.code === 1) {
console.log('提交成功:', response.msg)
uni.showToast({
title: '入职申请已提交,等待审批',
icon: 'success',
@ -606,16 +712,26 @@ export default {
uni.navigateBack()
}, 2000)
} else {
console.error('提交失败:', response.msg)
uni.showToast({
title: response.data.msg || '提交失败',
title: response.msg || '提交失败',
icon: 'none'
})
}
} catch (error) {
console.error('提交员工信息失败:', error)
//
let errorMsg = '网络错误,请稍后重试'
if (error.response) {
errorMsg = error.response.msg || `服务器错误(${error.response.status})`
} else if (error.message) {
errorMsg = error.message
}
uni.showToast({
title: '网络错误,请稍后重试',
icon: 'none'
title: errorMsg,
icon: 'none',
duration: 3000
})
} finally {
this.submitting = false

Loading…
Cancel
Save