增加单位管理的接口
This commit is contained in:
@@ -11,48 +11,51 @@
|
||||
<!-- 用户姓名 -->
|
||||
<view class="form-item">
|
||||
<text class="item-label required">用户姓名</text>
|
||||
<input class="item-input" type="text" placeholder="请输入"/>
|
||||
<input class="item-input" type="text" placeholder="请输入" v-model="employeeInfo.userName"/>
|
||||
</view>
|
||||
|
||||
<!-- 性别 -->
|
||||
<view class="form-item">
|
||||
<text class="item-label required">性别</text>
|
||||
<picker class="item-input" @change="bindPickerChange" :value="index" :range="array">
|
||||
<view class="picker-content">{{array[index]}}</view>
|
||||
<picker class="item-input" @change="bindPickerChange" :range="array"
|
||||
v-model="employeeInfo.gender">
|
||||
<view class="picker-content">{{ array[index] }}</view>
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
<!-- 证件号 -->
|
||||
<view class="form-item">
|
||||
<text class="item-label required">证件号</text>
|
||||
<input class="item-input" type="text" placeholder="请输入"/>
|
||||
<input class="item-input" type="text" placeholder="请输入" v-model="employeeInfo.idCard"
|
||||
@blur="validateIdCard"/>
|
||||
</view>
|
||||
|
||||
<!-- 联系电话 -->
|
||||
<view class="form-item">
|
||||
<text class="item-label required">联系电话</text>
|
||||
<input class="item-input" type="number" placeholder="请输入"/>
|
||||
<input class="item-input" type="number" placeholder="请输入" v-model="employeeInfo.phone"/>
|
||||
</view>
|
||||
|
||||
<!-- 验证码 -->
|
||||
<view class="form-item">
|
||||
<text class="item-label required">验证码</text>
|
||||
<view class="code-input-wrapper">
|
||||
<input class="item-input code-input" type="number" placeholder="请输入"/>
|
||||
<button class="get-code-btn">获取验证码</button>
|
||||
</view>
|
||||
</view>
|
||||
<!-- <!– 验证码 –>-->
|
||||
<!-- <view class="form-item">-->
|
||||
<!-- <text class="item-label required">验证码</text>-->
|
||||
<!-- <view class="code-input-wrapper">-->
|
||||
<!-- <input class="item-input code-input" type="number" placeholder="请输入"/>-->
|
||||
<!-- <button class="get-code-btn">获取验证码</button>-->
|
||||
<!-- </view>-->
|
||||
<!-- </view>-->
|
||||
|
||||
<!-- 登录密码 -->
|
||||
<view class="form-item">
|
||||
<text class="item-label required">登录密码</text>
|
||||
<input class="item-input" type="password" placeholder="请输入"/>
|
||||
<input class="item-input" type="password" placeholder="请输入" v-model="employeeInfo.password"
|
||||
@blur="validatePassword"/>
|
||||
</view>
|
||||
|
||||
<!-- 确认密码 -->
|
||||
<view class="form-item">
|
||||
<text class="item-label required">确认密码</text>
|
||||
<input class="item-input" type="password" placeholder="请输入"/>
|
||||
<input class="item-input" type="password" placeholder="请输入" v-model="rePassword" @blur="validatePassword"/>
|
||||
</view>
|
||||
|
||||
<!-- 密码提示 -->
|
||||
@@ -67,46 +70,66 @@
|
||||
<view class="face-upload-container">
|
||||
<view class="upload-wrapper">
|
||||
<button class="upload-btn" @click="chooseImage">+</button>
|
||||
<view class="image-preview" v-if="imageUrl">
|
||||
<image :src="imageUrl" mode="aspectFill" class="preview-image"></image>
|
||||
<view class="image-preview" v-if="employeeInfo.img">
|
||||
<image :src="employeeInfo.img" mode="aspectFill" class="preview-image"></image>
|
||||
<view class="delete-btn" @click="deleteImage">×</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="form-tip upload-tip">
|
||||
请上传正脸并不超过5MB的jpg,jpeg,png,gif,webp格式文件
|
||||
</view>
|
||||
<view class="form-tip upload-tip">
|
||||
请上传正脸并不超过5MB的jpg,jpeg,png,gif,webp格式文件
|
||||
</view>
|
||||
|
||||
<!-- 邮箱和车牌号码 -->
|
||||
<view class="form-item">
|
||||
<text class="item-label">邮箱</text>
|
||||
<input class="item-input" type="text" placeholder="请输入"/>
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="item-label">车牌号码</text>
|
||||
<input class="item-input" type="text" placeholder="请输入"/>
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="item-label">邮箱</text>
|
||||
<input class="item-input" type="text" placeholder="请输入" v-model="employeeInfo.email"/>
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="item-label">车牌号码</text>
|
||||
<input class="item-input" type="text" placeholder="请输入" v-model="employeeInfo.carNumber"/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 提交按钮 -->
|
||||
<button class="submit-btn">提交</button>
|
||||
<button class="submit-btn" @click="submitForm">提交</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {uploadFiles} from "../../../../common/upload";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
imageUrl: '', // 存储上传的图片URL
|
||||
array: ['男', '女'],
|
||||
index: 0,
|
||||
employeeInfo: {
|
||||
userName: '',
|
||||
gender: 1,
|
||||
idCard: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
img: '',
|
||||
unitId: '',
|
||||
email:'',
|
||||
carNumber:''
|
||||
},
|
||||
rePassword: '',
|
||||
passwordError: '', // 用于显示密码错误信息
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
if (options.unitId) {
|
||||
const unitId = JSON.parse(decodeURIComponent(options.unitId));
|
||||
this.employeeInfo.unitId = unitId;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
bindPickerChange: function(e) {
|
||||
console.log('picker发送选择改变,携带值为', e.detail.value)
|
||||
this.index = e.detail.value
|
||||
bindPickerChange: function (e) {
|
||||
|
||||
this.employeeInfo.gender = e.detail.value + 1
|
||||
console.log('picker发送选择改变,携带值为', this.employeeInfo.gender)
|
||||
},
|
||||
// 选择图片
|
||||
chooseImage() {
|
||||
@@ -114,16 +137,92 @@ export default {
|
||||
count: 1,
|
||||
sizeType: ['compressed'],
|
||||
sourceType: ['album', 'camera'],
|
||||
success: (res) => {
|
||||
success: async (res) => {
|
||||
const tempFilePaths = res.tempFilePaths;
|
||||
this.imageUrl = tempFilePaths[0];
|
||||
// 这里可以添加图片上传到服务器的逻辑
|
||||
this.employeeInfo.img = tempFilePaths[0];
|
||||
console.log(tempFilePaths);
|
||||
// 图片上传到服务器的逻辑
|
||||
const result = await uploadFiles({
|
||||
files: tempFilePaths,
|
||||
url: this.vuex_config.baseUrl + '/resource/oss/upload',
|
||||
name: 'file',
|
||||
vm: this // 关键:用于注入 token 等
|
||||
});
|
||||
const allSuccess = result.every(item => item.code == 200);
|
||||
if (!allSuccess) {
|
||||
uni.showToast({
|
||||
title: '上传失败',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
// 删除图片
|
||||
deleteImage() {
|
||||
this.imageUrl = '';
|
||||
this.employeeInfo.img = '';
|
||||
}, // 提交表单
|
||||
submitForm() {
|
||||
//密码对比
|
||||
if (!this.validatePassword()) {
|
||||
uni.showToast({
|
||||
title: this.passwordError,
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
//身份证验证
|
||||
if (!this.validateIdCard()) {
|
||||
uni.showToast({
|
||||
title: "身份证格式不正确",
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.$u.api.unit.addEmployee(this.employeeInfo).then(res => {
|
||||
if (res.code == "200") {
|
||||
// 提交逻辑
|
||||
console.log('提交数据:', this.employeeInfo);
|
||||
uni.showToast({
|
||||
title: '提交成功',
|
||||
icon: 'success'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
// 密码验证方法
|
||||
validatePassword() {
|
||||
// 密码正则表达式:8-20位,包含大小写字母、数字和特殊字符
|
||||
const passwordRegex = /^(?=.*[a-zA-Z\d!@$%^&*$%&+&*=\[\]?])[a-zA-Z\d!@$%^&*$%&+&*=\[\]?]{8,20}$/;
|
||||
|
||||
// 验证密码格式
|
||||
if (!passwordRegex.test(this.employeeInfo.password)) {
|
||||
this.passwordError = '密码必须包含8-20位大小写字母、数字和特殊字符';
|
||||
return false;
|
||||
} else {
|
||||
this.passwordError = '';
|
||||
}
|
||||
|
||||
// 验证两次密码是否一致
|
||||
if (this.employeeInfo.password !== this.rePassword) {
|
||||
this.passwordError = '两次输入的密码不一致';
|
||||
return false;
|
||||
} else {
|
||||
this.passwordError = '';
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
validateIdCard() {
|
||||
const idCardRegex = /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/;
|
||||
if (!idCardRegex.test(this.employeeInfo.idCard)) {
|
||||
uni.showToast({title: '身份证格式错误', icon: 'none'});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,26 +331,6 @@ export default {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* 上传区域 */
|
||||
.upload-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.upload-btn {
|
||||
width: 80px;
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
font-size: 14px;
|
||||
color: #409eff;
|
||||
background-color: #ecf5ff;
|
||||
border: 1px solid #b3d8ff;
|
||||
border-radius: 4px;
|
||||
margin-right: 10px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* 提交按钮 */
|
||||
.submit-btn {
|
||||
width: 100%;
|
||||
@@ -271,19 +350,7 @@ export default {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.upload-btn {
|
||||
width: 60px; /* 正方形 */
|
||||
height: 60px; /* 正方形 */
|
||||
line-height: 40px;
|
||||
font-size: 40px; /* 加大+号 */
|
||||
color: #409eff;
|
||||
background-color: #ecf5ff;
|
||||
border: 1px solid #b3d8ff;
|
||||
border-radius: 4px;
|
||||
margin-right: 10px;
|
||||
padding: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.face-upload-item {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
@@ -345,4 +412,6 @@ export default {
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
Reference in New Issue
Block a user