我的页和设置页完成

This commit is contained in:
田岩
2025-06-27 17:08:58 +08:00
parent ece5e7e1a9
commit a9ccdd2b95
22 changed files with 3298 additions and 133 deletions
+3 -5
View File
@@ -9,14 +9,12 @@ ENV = 'development'
# VITE_APP_BASE_API_Url = 'http://25.64.16.133:9786'
# VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7001'
VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7001'
app入口
<<<<<<< HEAD
VITE_APP_BASE_API_Url = 'http://25.18.122.65:7001'
=======
# VITE_APP_BASE_API_Url = 'http://25.18.122.65:7001'
# VITE_APP_BASE_API_Url = 'http://25.16.122.65:7001'
# VITE_APP_BASE_API_Url = 'http://25.18.122.66:9786'
>>>>>>> f9ef91e5fe7dbec56a29867b9d2d9f7e3792f0f4
+68 -14
View File
@@ -2,9 +2,12 @@ import request from '@/api/request'
import common from "@/common/common";
import {
setToken,
setUserInfo
setUserInfo,
getUserInfo
} from "@/common/common";
import {
get_base_url
} from '@/api/request.js'
// 账号登录接口
export const useAccountLoginApp = (data) => request({
@@ -17,17 +20,10 @@ export const useAccountLoginApp = (data) => request({
}) => {
if (rtnCode === '0000') {
setToken(body)
// deptId: ""
// deptName: null
// loginName: "ADMIN" // todo id
// orgId: "00E200"
// orgName: "金融科技部"
// userId: "USER001"
// userName: "ADMIN" / todo name
// userStatus: "01"
const user_data = await queryCurrentUser()
setUserInfo(user_data.body)
return user_data.body
return user_data
}
return Promise.reject({
rtnCode,
@@ -49,14 +45,14 @@ export const useAccountLoginApp = (data) => request({
rtnCode: "9999"
rtnTime: "2025-06-24 08:54:52"
*/
return Promise.reject(res)
})
/**
* 获取个人信息
* 入参
gender F是女 M
gender f是女 m
imageAddr 图片
loginName ID
userName 姓名
@@ -65,6 +61,64 @@ export const queryCurrentUser = (data) => request({
url: '/traapp/access/queryCurrentUser',
method: 'post',
data
}).then(res => {
// deptId: ""
// deptName: null
// loginName: "ADMIN" // todo id
// orgId: "00E200"
// orgName: "金融科技部"
// userId: "USER001"
// userName: "ADMIN" / todo name
// userStatus: "01"
setUserInfo(res.body)
console.log('预加载头像');
const base_url = get_base_url()
// 预加载头像
// #ifdef APP-PLUS
const updateUserAvatar = (imagePath) => {
const userInfo = getUserInfo()
setUserInfo({
...userInfo,
'imagePath': imagePath
})
}
try {
const pathName = res.body.imageAddr
const url = base_url + pathName
// 生成唯一文件名,避免冲突
const filename = pathName.split('/').pop()
const localFilePath = '_downloads/' + filename
// 先检查是否存在
uni.getFileInfo({
filePath: localFilePath,
success: () => {
console.log('头像已存在,无需下载');
updateUserAvatar(localFilePath)
},
fail: () => {
console.log('开始下载头像:', url);
const dtask = plus.downloader.createDownload(
url, {
method: 'GET',
filename: '_downloads/' + filename
},
(download, status) => {
if (status === 200) {
console.log('头像下载成功:', download.filename);
updateUserAvatar(download.filename)
}
}
)
dtask.start();
}
})
} catch (error) {
console.error('头像预加载过程发生错误:', error);
}
// #endif
return res.body
})
//获取隐私协议
+7 -2
View File
@@ -50,7 +50,8 @@ export default function request({
meta,
isStream,
suppressErrors,
header = {}
header = {},
timeout = 6000
}) {
const base_url = get_base_url(url);
@@ -70,6 +71,7 @@ export default function request({
data: data,
method: method,
header: headers_base,
timeout:timeout,
success: (response) => {
if (isStream) { // 流式传输,直接返回
return resolve(response);
@@ -92,11 +94,14 @@ export default function request({
if (REQUES_ERROR_CODES['NO_LOGIN'].includes(res.rtnCode)) {
goto_login_fun()
}
if (res?.rtnCode === '9999') {
common.msg("系统异常.")
}
return reject(res)
},
fail(res) {
console.log('请求错误', res, url, base_url);
return reject(res)
}
});
})
+24 -3
View File
@@ -12,7 +12,28 @@ export const queryTraStdyStatisticsSelf = (data) => {
return request({
url: '/traapp/traStdyInfo/queryTraStdyStatisticsSelf',
method: 'post',
data,
suppressErrors: true
data
});
};
};
// 更新性别
export const updateDfSysUserExtandInfoGender = (data) => {
/**
**/
return request({
url: '/traapp/dfSysUserInfo/updateDfSysUserExtandInfoGender ',
method: 'post',
data
});
};
// 更新照片
export const updateDfSysUserExtandInfoImageAddr = (data) => {
return request({
url: '/traapp/dfSysUserInfo/updateDfSysUserExtandInfoImageAddr',
method: 'post',
data
});
};
File diff suppressed because it is too large Load Diff
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.3.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="30px" height="30px" viewBox="0 0 30 30" style="enable-background:new 0 0 30 30;" xml:space="preserve">
<style type="text/css">
.st0{fill:none;stroke:#FFFFFF;stroke-width:2.4306;stroke-miterlimit:10;}
.st1{fill:#FFFFFF;}
</style>
<g>
<path class="st0" d="M17.1,24.2h-12c-0.2,0-0.3-0.2-0.3-0.3v-9.3c0-0.2,0.2-0.3,0.3-0.3h12c0.2,0,0.3,0.2,0.3,0.3v9.3
C17.5,24.1,17.3,24.2,17.1,24.2z"/>
<path class="st0" d="M16.6,5.4c4.8,0,8.7,3.9,8.7,8.7"/>
<polyline class="st0" points="19.3,10.1 14.9,5.6 19.3,1.2 "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 791 B

+19 -1
View File
@@ -4,6 +4,7 @@
<script>
import {previewFile, previewCacheThumbImage} from'@/api/common.js'
import {get_base_url} from '@/api/request.js'
export default {
name:"image-preview",
props:{
@@ -11,6 +12,10 @@
default:'',
type:String
},
src:{
default:'',
type:String
},
width:{
default:50,
type:[String, Number]
@@ -27,7 +32,8 @@
data() {
return {
imgUrlShow: '',
watching: false
watching: false,
base_url: get_base_url()
};
},
watch: {
@@ -39,6 +45,15 @@
},
immediate: true,
deep: true,
},
src: {
handler(newval, oldval) {
if (newval && this.watching) {
this.imgUrlShow = this.base_url + this.src
}
},
immediate: true,
deep: true,
}
},
methods: {
@@ -70,6 +85,9 @@
this.getPreviewUrlBlob(this.imgId);
}
this.watching = true
if(this.src) {
this.imgUrlShow = this.base_url + this.src
}
}
}
</script>
@@ -109,25 +109,15 @@
const data = {
bizScen: 'S3005'
}
console.log(tempFilePaths[0]);
const upload_map = tempFilePaths.map((file) => uploadFile(file, data))
Promise.all(upload_map).then(res => {
fileList.push(...res)
emits('update:modelValue', fileList.map(res => res.fileId))
console.log('res, res', res);
}).catch(() => {
})
// for (file of tempFilePaths) {
// try {
// const res = await uploadFile(file, data)
// console.log('res', res);
// fileList.push(res)
// } catch (error) {
// console.error('文件上传失败', error)
// }
// }
// emits('upload_success', fileList.value)
}
})
}
+16 -7
View File
@@ -1,7 +1,16 @@
MaxUploadPictureSize = 2048 // 最大图片上传限制
MaxUploadDocumentMaxSize = 102400 // 最大文档上传限制
500
export const MAX_UPLOAD_PICTURE_SIZE = 2048 // 最大图片上传限制
export const Max_Upload_Document_Size = 102400 // 最大文档上传限制
export const TextareaInputLimitCharacter = 160 // 全局多行文本输入框限制字数
export const GENDER = [{
value: "m",
label: "男性",
},
{
value: "f",
label: "女性",
},
{
value: "o",
label: "其他",
}
] // 性别
@@ -15,7 +15,7 @@
</view>
<view class="title">
{{item.bbsContent}}
</view>azf
</view>
<view class="img_div pic-cell">
<image-preview v-for="img in item.imgIdList" :imgId="img" class="pic-item"></image-preview>
</view>
+34
View File
@@ -1,6 +1,9 @@
<template>
<view class="max_page detail-main" style="overflow: hidden;">
<image src="/src/static/images/courseDetail/mipmap-xhdpi/bg.png" mode="widthFix" class="back-image"></image>
<view class="back_div" @click="common.navigateBack()">
<view class="back-icon"></view>
</view>
<view class="detail-body">
<view class="head-title font_pf">
<view class="title-text">{{ form.crsName }}</view>
@@ -101,6 +104,37 @@
</script>
<style lang="scss" scoped>
.back_div {
margin-right: 10rpx;
position: absolute;
left: 46rpx;
top: 64rpx;
.back-icon {
position: relative;
width: 40rpx;
height: 40rpx;
cursor: pointer;
}
.back-icon::before,
.back-icon::after {
content: '';
position: absolute;
transition: all 0.3s ease;
}
.back-icon::after {
top: 25%;
left: 25%;
width: 40%;
height: 40%;
border-top: 4rpx solid #FFFFFF;
border-left: 4rpx solid #FFFFFF;
transform: rotate(-45deg);
}
}
.detail-main {
background-color: #f5f5f5;
position: relative;
+3 -2
View File
@@ -41,13 +41,13 @@
提问</view>
</view>
<view class="input-textarea">
<uv-textarea v-model="formData.bbsContent" height="124" count
<uv-textarea v-model="formData.bbsContent" height="124" count :maxlength="TextareaInputLimitCharacter"
:placeholder="formData.bbsTag == 'SUG'?'请输入你的建议...':'请输入你的问题...'"></uv-textarea>
</view>
</view>
</view>
<view class="btn-box font_pf">
<uv-button type="primary" @click="submit">提交评价</uv-button>
<uv-button type="primary" @click="submit" :disabled="!formData.bbsContent">提交评价</uv-button>
</view>
</view>
</template>
@@ -57,6 +57,7 @@
reactive,
ref
} from 'vue';
import {TextareaInputLimitCharacter} from "@/enum.js"
import {
onLoad
} from '@dcloudio/uni-app';
+7 -4
View File
@@ -252,6 +252,7 @@
const stdtTmLenRef = ref(null);
const accmPracticeCntRef = ref(null);
const accmExamCntRef = ref(null);
const three_list_request_time = ref(0); // 三个列表更新时间
// 计算透明度
const opacity = computed(() => {
@@ -304,7 +305,7 @@
"get_statistics_data": async function() {
try {
const time_now = Date.now();
if (time_now - this.request_time > 30) {
if (time_now - this.request_time > 300 * 1000) {
this.request_time = time_now;
// 获取最新数据
const res = await getStatisticsData();
@@ -333,7 +334,7 @@
console.log('时间没到无需更新');
}
} catch (error) {
console.error('获取统计数据失败:', error);
console.log('获取统计数据失败:', error);
}
}
});
@@ -347,13 +348,12 @@
common.navigateTo('/pages/courseDetail/index?crsNum=' + crsNum)
}
onShow(() => {
console.log('onShow');
if(!common.isLogin()){
common.navigateTo('/pages/login/login')
return
}
statistics_data['get_statistics_data']() // 获取统计数据
})
onMounted(async () => {
if(!common.isLogin()) return;
queryCrsInfoByLastnew().then(res => {
new_class_list.value = res.body
@@ -365,6 +365,9 @@
recommend_class_list.value = res.body
})
})
onLoad(async () => {
})
</script>
+8 -4
View File
@@ -8,7 +8,9 @@
<!-- 用户个人信息 -->
<view class="personal_information">
<view class="profile">
<image v-if="user_info.imageAddr" class="img_100" src="/static/images/test/touxiang.png"></image>
<!-- <image-preview v-if="user_info.imageAddr" class="img_100" :src="user_info.imageAddr"></image-preview> -->
<image v-if="user_info.imagePath" class="img_100" :src="user_info.imagePath"></image>
<image-preview v-else-if="user_info.imageAddr" class="img_100" :src="user_info.imageAddr"></image-preview>
<image v-else class="img_100" src="/static/images/me/default_user_avatar.png"></image>
</view>
<view class="personal_information_data">
@@ -17,8 +19,8 @@
{{ user_info.userName }}
</view>
<view class="sex">
<image v-if="user_info.gender === 'F'" class="img_100" src="/static/images/me/wuman.png"></image>
<image v-if="user_info.gender === 'M'" class="img_100" src="/static/images/me/man.png"></image>
<image v-if="user_info.gender === 'f'" class="img_100" src="/static/images/me/wuman.png"></image>
<image v-if="user_info.gender === 'm'" class="img_100" src="/static/images/me/man.png"></image>
</view>
</view>
<view class="work_number_div">工号{{ user_info.userId }}</view>
@@ -108,6 +110,7 @@ import { getUserInfo } from '@/common/common';
import { onPullDownRefresh } from '@dcloudio/uni-app';
import { loginOut } from '@/api/login.js';
import { queryTraStdyStatisticsSelf } from '@/api/user.js';
const accmTaskCntRef = ref(null);
const accmPointRef = ref(null);
const stdtTmLenRef = ref(null);
@@ -169,7 +172,8 @@ const statistics_data = reactive({
const user_info = reactive({
userName: '',
userId: ''
userId: '',
imageAddr: '',
});
onShow(() => {
+186 -77
View File
@@ -8,14 +8,15 @@
<view class="title font_pf">设置</view>
</view>
<view class="detail-body">
<uv-cell-group>
<uv-cell-group :border="false">
<uv-cell @click="cellCLick" name="avatar" isLink title="头像">
<template #title>
<view class="font_pf">头像</view>
</template>
<template #value>
<view style="width: 60rpx; height: 60rpx; border-radius: 100%; overflow: hidden">
<image style="width: 100%" src="/src/static/images/test/touxiang.png" mode="widthFix"></image>
<view style="width: 42rpx; height: 42rpx;border-radius: 100%; overflow: hidden">
<image-preview style="width: 100%" v-if="userInfo.imageAddr" :src="userInfo.imageAddr"></image-preview>
</view>
</template>
</uv-cell>
@@ -24,98 +25,206 @@
<text class="font_pf">性别</text>
</template>
<template #value>
<picker mode="selector" :value="index" range-key="label" style="width: 100%" :range="sexOptions" @change="sexChange">
<view style="text-align: right">{{ sexOptions.find((item) => item.value == form.gender).label || '' }}</view>
<picker mode="selector" :value="index" range-key="label" style="width: 100%" :range="sexOptions"
@change="sexChange">
<view style="text-align: right">{{showGenderText}}</view>
</picker>
</template>
</uv-cell>
<uv-cell title="形象" :isLink="true" :border="false"></uv-cell>
</uv-cell-group>
</view>
<avatar-cropper v-if="avatarCropperStatus" mode="ratio" :imageUrl="avatarCropperUrl" :width="500" :height="500"
:delay="150" @cancel="onCancel" @confirm="onConfirm"></avatar-cropper>
</view>
</template>
<script setup>
import { reactive, ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import common from '@/common/common';
const index = ref(0);
const form = ref({
gender: 'Y'
});
const sexOptions = [
{ value: 'Y', label: '男' },
{ value: 'M', label: '女' }
];
const cellCLick = (value) => {};
const sexChange = (e) => {
console.log(e);
console.log(sexOptions[e.detail.value].value, 'sexOptions[e.detail.value].value');
form.value.gender = sexOptions[e.detail.value].value;
import {
reactive,
ref,
computed,
nextTick
} from 'vue';
import {
onLoad
} from '@dcloudio/uni-app';
import {
uploadFile
} from '@/api/common'
import { queryCurrentUser} from '@/api/login.js';
import common from '@/common/common';
import {getUserInfo} from '@/common/common';
import {
GENDER
} from '@/enum.js';
import {
updateDfSysUserExtandInfoGender,
updateDfSysUserExtandInfoImageAddr
} from "@/api/user.js"
const index = ref(0);
const avatarCropperUrl = ref('');
const aaa = ref('');
const userInfo = ref({
gender: '',
imageAddr: ''
});
const avatarCropperStatus = ref(true)
const sexOptions = GENDER
const showGenderText = computed(() => {
const item = sexOptions.find((item) => item.value == userInfo.value.gender)
if (item) {
return item.label
} else {
return '未填写'
}
})
const onCancel = (value) => {
avatarCropperStatus.value = false
}
const onConfirm = (file) => {
avatarCropperStatus.value = false
nextTick(async() => {
common.loading('更新头像中')
try{
const data = {
bizScen: 'S3010',
thumbnailFlag: true,
thumbImgSize:100
}
// 上传图片
const res = await uploadFile(file.tempFilePath, data)
// 更新个人信息
await updateDfSysUserExtandInfoImageAddr({imageAddr : res.thumbFileId})
// 更新个人信息
const userData = await queryCurrentUser()
common.msg('修改成功')
console.log(userData);
userInfo.value.imageAddr = getUserInfo('imageAddr')
} catch {
common.msg('修改失败')
}
common.hideLoading()
})
}
console.log(form.value.gender, 'iiii');
};
onLoad((params) => {});
const cellCLick = (value) => {
uni.chooseImage({
count: 1,
sizeType: ["compressed"],
success: (res) => {
avatarCropperUrl.value = res.tempFilePaths[0];
avatarCropperStatus.value = true
},
});
};
const sexChange = (e) => {
userInfo.value.gender = sexOptions[e.detail.value].value;
common.loading("修改中")
updateDfSysUserExtandInfoGender({
gender: userInfo.value.gender
}).then(res => {
common.msg('修改成功')
}).finally(() => {
common.hideLoading()
})
};
onLoad((params) => {
userInfo.value = getUserInfo()
console.log(userInfo.value);
});
</script>
<style lang="scss" scoped>
.detail-main {
background-color: #fff;
}
$bg-margin-left: 50rpx;
.detail-body {
box-sizing: border-box;
min-height: calc(100vh - (var(--status-bar-height)+50rpx));
// padding: 29rpx 37rpx;
width: 100%;
display: flex;
flex-direction: column;
padding-top: 0rpx;
:deep(.uv-cell__title) {
flex: none !important;
}
}
.detail-body {
margin: 30rpx $bg-margin-left 0 $bg-margin-left;
background: #ffffff;
// background: red;
border-radius: 15rpx;
z-index: 101;
overflow: hidden;
.title {
color: #000000;
font-size: 34rpx;
height: 34rpx;
font-weight: 600;
// margin-bottom: 30rpx;
line-height: 34rpx;
}
.fixed_search_div {
padding: calc(10rpx + var(--status-bar-height)) 15rpx 24rpx 30rpx;
display: flex;
align-items: center;
background-color: #f6f7f8;
.back_div {
margin-right: 10rpx;
.back-icon {
position: relative;
width: 40rpx;
height: 40rpx;
cursor: pointer;
display: flex;
align-items: center;
// 为了让线缩进来24单位
:deep(.uv-line) {
width: calc(100% - 48rpx) !important;
margin: 0 24rpx !important;
}
.back-icon::before,
.back-icon::after {
content: '';
position: absolute;
transition: all 0.3s ease;
:deep(.uv-cell__body) {
padding: 12px 15px;
}
.back-icon::after {
top: 25%;
left: 25%;
width: 40%;
height: 40%;
border-top: 4rpx solid #2b2c2e;
border-left: 4rpx solid #2b2c2e;
transform: rotate(-45deg);
:deep(.uv-cell__title) {
flex: none !important;
}
}
}
</style>
.detail-main {
background-color: #F6F8FF;
}
// .detail-body {
// box-sizing: border-box;
// min-height: calc(100vh - (var(--status-bar-height)+50rpx));
// // padding: 29rpx 37rpx;
// width: 100%;
// display: flex;
// flex-direction: column;
// padding-top: 0rpx;
// }
.title {
color: #000000;
font-size: 34rpx;
height: 34rpx;
font-weight: 600;
// margin-bottom: 30rpx;
line-height: 34rpx;
}
.fixed_search_div {
padding: calc(10rpx + var(--status-bar-height)) 15rpx 24rpx 30rpx;
display: flex;
align-items: center;
background-color: #f6f7f8;
.back_div {
margin-right: 10rpx;
.back-icon {
position: relative;
width: 40rpx;
height: 40rpx;
cursor: pointer;
display: flex;
align-items: center;
}
.back-icon::before,
.back-icon::after {
content: '';
position: absolute;
transition: all 0.3s ease;
}
.back-icon::after {
top: 25%;
left: 25%;
width: 40%;
height: 40%;
border-top: 4rpx solid #2b2c2e;
border-left: 4rpx solid #2b2c2e;
transform: rotate(-45deg);
}
}
}
</style>
+18
View File
@@ -0,0 +1,18 @@
## 1.0.82024-09-13
新增矩形框最大缩放、修复图片旋转时居中
## 1.0.72024-08-08
优化选择大文件图片后,无法在Image中直接显示图片,提供针对大图片压缩思路
## 1.0.62024-06-16
优化确定按钮,快速重复点击出现多个裁剪图片,更新了文档
## 1.0.52023-11-16
优化裁剪框圆角/裁剪图片圆角,更新了文档
## 1.0.42023-11-14
支持图片最大缩放功能,优化App端图标问题,
## 1.0.32023-11-11
新增图片旋转图标rotate.svg
## 1.0.22023-11-11
新增H5端和App端(Android端通过自测,Ios端没有设备暂未自测)
## 1.0.12023-11-10
新增项目示例
## 1.0.02023-11-10
图片裁剪工具
@@ -0,0 +1,202 @@
$clipper-edge-border-width: 6rpx !default;
.t-cropper {
position: fixed;
width: 100%;
height: 100%;
top: 0;
bottom: 0;
z-index: 1000;
overflow: hidden;
.canvas {
position: absolute;
top: 5000px;
left: 5000px;
}
// 裁剪区域
.t-preview-container {
position: fixed;
width: 100%;
height: 100%;
top: 0;
bottom: 0;
z-index: 1000;
opacity: 0;
overflow: hidden;
.preview-body {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: #000;
overflow: hidden;
.mask-model {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: #000;
opacity: 0.4;
pointer-events: none;
}
.image-wrap {
position: absolute;
.image {
position: absolute;
}
}
// 裁剪框盒子
.frame-box {
position: absolute;
left: 100px;
top: 100px;
width: 200px;
height: 200px;
// 矩形图片
.rect {
position: absolute;
left: -2px;
top: -2px;
width: 100%;
height: 100%;
border: 2rpx solid white;
overflow: hidden;
box-sizing: content-box;
.image-rect {
position: absolute;
.rect-img {
position: absolute;
}
}
}
//裁剪框线条
.line-one {
position: absolute;
width: 100%;
border-top: 1px dashed #ccc;
left: 0;
top: 33.3%;
box-sizing: content-box;
}
.line-two {
position: absolute;
width: 100%;
border-top: 1px dashed #ccc;
left: 0;
top: 66.7%;
box-sizing: content-box;
}
.line-three {
position: absolute;
height: 100%;
border-right: 1px dashed #ccc;
top: 0;
left: 33.3%;
box-sizing: content-box;
}
.line-four {
position: absolute;
height: 100%;
border-right: 1px dashed #ccc;
top: 0;
left: 66.7%;
box-sizing: content-box;
}
.frame-left-top {
position: absolute;
width: 20px;
height: 20px;
left: -8rpx;
top: -8rpx;
border-left: 4rpx solid #fff;
border-top: 4rpx solid #fff;
box-sizing: content-box;
}
.frame-left-bottom {
position: absolute;
width: 20px;
height: 20px;
left: -8rpx;
bottom: -4rpx;
border-left: 4rpx solid #fff;
border-bottom: 4rpx solid #fff;
box-sizing: content-box;
}
.frame-right-top {
position: absolute;
width: 20px;
height: 20px;
right: -4rpx;
top: -8rpx;
border-right: 4rpx solid #fff;
border-top: 4rpx solid #fff;
box-sizing: content-box;
}
.frame-right-bottom {
position: absolute;
width: 20px;
height: 20px;
right: -4rpx;
bottom: -4rpx;
border-right: 4rpx solid #fff;
border-bottom: 4rpx solid #fff;
box-sizing: content-box;
}
}
}
// 底部工具栏
.toolbar {
position: absolute;
width: calc(100% - 64rpx);
height: 100rpx;
left: 0;
bottom: 10rpx;
text-align: center;
display: flex;
justify-content: space-between;
padding: 0 32rpx;
align-items: center;
// IOS 底部安全距离
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
.btn-cancel {
width: 112rpx;
font-size: 28rpx;
color: #d5dfe5;
font-weight: bold;
}
.btn-rotate {
width: 112rpx;
font-size: 28rpx;
color: #d5dfe5;
font-weight: bold;
image {
width: 60rpx;
height: 60rpx;
}
}
.btn-confirm {
font-size: 28rpx;
color: #ffffff;
font-weight: bold;
width: 112rpx;
height: 60rpx;
line-height: 60rpx;
background: #07c160;
border-radius: 6rpx;
text-align: center;
}
}
.transit {
transition: width 0.3s, height 0.3s, left 0.3s, top 0.3s, transform 0.3s;
}
}
.showPage {
opacity: 1 !important;
}
}
File diff suppressed because it is too large Load Diff
+85
View File
@@ -0,0 +1,85 @@
{
"id": "t-cropper",
"displayName": "t-cropper图片裁剪插件",
"version": "1.0.8",
"description": "vue3图片裁剪插件,头像裁剪、支持自定义尺寸、等比例缩放、拖动、图片翻转、剪切圆形/圆角图片,高性能裁剪图片插件",
"keywords": [
"图片裁剪",
",头像裁剪,缩放,旋转,拖动",
""
],
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"type": "component-vue",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y",
"alipay": "n"
},
"client": {
"Vue": {
"vue2": "n",
"vue3": "y"
},
"App": {
"app-vue": "y",
"app-nvue": "u",
"app-uvue": "u"
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "y",
"阿里": "y",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
+186
View File
@@ -0,0 +1,186 @@
# t-cropper
> **t-cropper 一款高性能移动端图片裁剪工具**
## 平台兼容
| App | H5 | 微信小程序 | 支付宝小程序 |
| :---: | :---: | :----------: | :-----------: |
| √ | √ | √ | √ |
### 属性说明
|属性 |类型 |默认 |备注 |
| :--------: | :-----: | :----: | :----: |
| mode |String | "ratio" | 裁剪模式|
| imageUrl |String | " " | 需要裁剪的图片路径|
| width |Number | 200 | 图片裁剪后的宽度,固定大小时有效|
| height |Number | 200 | 图片裁剪后的高度,固定大小时有效|
| maxWidth |Number | 1024 | 图片裁剪后的最大宽度 |
| maxHeight |Number | 1024 | 图片裁剪后的最大高度 |
| scaleRatio |Number | 0.7 | 裁剪比列缩放,建议不超过0.95 |
| minRatio |Number | 1 | 最小缩放 |
| maxRatio |Number | 3 | 最大缩放 |
| radius |Number | 0 | 裁剪图片圆角半径,单位px |
| delay |Number | 250 | 确定按钮快速重复点击时间 |
| isRotateBtn |Boolean | true | 是否显示旋转按钮 |
### mode有效值
| 模式 |值 |说明 |
| :-----: | :-----: | :----: |
| 固定模式 |fixed | 裁剪出指定大小的图片,一般用于头像上传 |
| 等比缩放 |ratio | 限定宽高比,裁剪大小不固定 |
| 自由模式 |free | 不限定宽高比,裁剪大小不固定 |
### 事件说明
|事件名称 |说明 |返回 |
| :--------: | :-----: | :----: |
| confirm |点击确定按钮 | object |
| cancel |点击取消按钮 | - |
### 示例
```html
<template>
<view>
<t-cropper
mode="ratio"
:imageUrl="imageUrl"
:width="500"
:height="500"
:radius="100"
:delay="150"
@cancel="onCancel"
@confirm="onConfirm"
></t-cropper>
<view class="preview">
<image
v-for="(item, index) in resultUrl"
:key="item.id"
class="images"
@click="prviewImgae(index, item.url)"
:src="item.url"
/>
</view>
<button class="button" type="primary" @click="selectFile">选择图片</button>
</view>
</template>
<script setup>
import { reactive, toRefs } from "vue";
const model = reactive({
imageUrl: "",
resultUrl: [],
});
const { resultUrl, imageUrl } = toRefs(model);
// 使用uni.compressImage压缩图片
const compressImage = () => {
uni.chooseImage({
count: 1,
sizeType: "original",
success: (res) => {
console.log("original", res);
// 示例:防止大图片文件的Image无法直接临时路径显示图片
uni.showLoading({
title: "处理中...",
mask: true,
});
// 使用uni.compressImage压缩图片
uni.compressImage({
src: res.tempFilePaths[0],
quality: 80, // 压缩质量
success: (compressRes) => {
model.imageUrl = compressRes.tempFilePath;
},
fail: (err) => {
console.error("图片压缩失败:", err);
},
complete: () => {
uni.hideLoading(); // 关闭loading
},
});
},
});
};
// 使用默认压缩方式
const defaultCompressImage = () => {
uni.chooseImage({
count: 1,
sizeType: "compressed",
success: (res) => {
model.imageUrl = res.tempFilePaths[0];
},
});
};
/**
*** 特别声明:在使用 uni.chooseImage 选择的大图片文件无法直接在 Image 组件中显示,通常涉及到以下可能的问题和限制。
*** 图片大小和尺寸限制:移动设备和浏览器对于能够加载和处理的图片大小有限制,如果选择的图片文件尺寸过大,可能无法正常加载和显示。
*** 性能问题:大图片文件可能会导致页面加载缓慢或者卡顿,尤其是在移动设备上。
*** 内存问题:加载大图片可能会消耗大量的内存资源,特别是在移动设备上,可能导致内存不足或者页面崩溃的问题。
*** 解决参考方案如下:
*** 防止选择大文件图片后无法在Image中直接临时路径显示图片,导致无法在裁剪插件中显示,
*** 根据项目需要对大尺寸图片进行压缩、对图片质量要求高的,需要提前上传至oss进行采用网络图片进行裁剪。
*/
const selectFile = () => {
// 推荐使用其他压缩方式,这里只是简单大图片压缩示例-经供思路参考切勿使用
// 示例一:uni.compressImage压缩图片
// compressImage();
// 示例二:使用自带压缩图
defaultCompressImage();
};
// 关闭裁剪
const onCancel = () => {
model.imageUrl = "";
};
// 裁剪确认
const onConfirm = (res) => {
// 设置url的值,显示控件
const params = {
id: new Date().getTime(),
url: res.tempFilePath,
};
model.resultUrl.push(params);
model.imageUrl = "";
};
// 预览图片
const prviewImgae = (index, url) => {
uni.previewImage({
current: index, // 当前资源下标
urls: [url],
});
};
</script>
<style lang="scss" scoped>
.preview {
padding: 32rpx;
.images {
margin: 10rpx;
width: 200rpx;
height: 200rpx;
}
}
.button {
margin: 0 20rpx;
}
</style>
```
### 注意
1.uni-app版本不断更新,插件有时无法适应新版本,感谢大家及时提交bug,但希望大家手下留情,不要轻易给差评!
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.3.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="30px" height="30px" viewBox="0 0 30 30" style="enable-background:new 0 0 30 30;" xml:space="preserve">
<style type="text/css">
.st0{fill:none;stroke:#FFFFFF;stroke-width:2.4306;stroke-miterlimit:10;}
.st1{fill:#FFFFFF;}
</style>
<g>
<path class="st0" d="M17.1,24.2h-12c-0.2,0-0.3-0.2-0.3-0.3v-9.3c0-0.2,0.2-0.3,0.3-0.3h12c0.2,0,0.3,0.2,0.3,0.3v9.3
C17.5,24.1,17.3,24.2,17.1,24.2z"/>
<path class="st0" d="M16.6,5.4c4.8,0,8.7,3.9,8.7,8.7"/>
<polyline class="st0" points="19.3,10.1 14.9,5.6 19.3,1.2 "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 791 B

@@ -101,7 +101,7 @@ export default {
// 最大输入长度,设置为 -1 的时候不限制最大长度
maxlength: {
type: [String, Number],
default: 140
default: 160
},
// 边框类型,surround-四周边框,bottom-底部边框
border: {