| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 |
- <template>
- <view class="page-container">
- <!-- 背景图 -->
- <image class="bg-image" src="/static/images/profile/1.png" mode="widthFix"></image>
- <scroll-view class="page-content" style="flex: 1">
- <!-- 用户信息头部 -->
- <view class="header">
- <image class="avatar" src="/static/images/login/2.png" mode="aspectFill"></image>
- <text class="user-name">{{ nickName }}({{ userName }})</text>
- </view>
- <!-- 信息卡片区域 -->
- <view class="info-cards">
- <!-- 电话卡片 -->
- <view class="info-card">
- <image class="card-icon" src="/static/images/profile/2.png" mode="aspectFit"></image>
- <text class="card-label">电话</text>
- <text class="card-value">{{ userPhone }}</text>
- </view>
- <!-- 部门卡片 -->
- <view class="info-card">
- <image class="card-icon" src="/static/images/profile/3.png" mode="aspectFit"></image>
- <text class="card-label">部门</text>
- <text class="card-value">{{ userDept }}</text>
- </view>
- </view>
- <!-- 通讯录 -->
- <view class="contact-item">
- <text class="contact-text">{{userRole}}</text>
- </view>
- <view class="menu-section">
- <view class="menu-item" @click="handlePassword()">
- <image class="menu-icon" src="/static/images/profile/7.png" mode="aspectFit"></image>
- <text class="menu-title">修改密码</text>
- <text class="menu-arrow">›</text>
- </view>
-
- <view class="menu-item">
- <image class="menu-icon" src="/static/images/profile/5.png" mode="aspectFit"></image>
- <text class="menu-title">版本:{{version}}</text>
- <text class="menu-title-download" v-if="isNewVersion" @click="handleVersionClick()">新版下载</text>
- </view>
- </view>
- <!-- 功能菜单 -->
- <!-- <view class="menu-section">
- <view v-for="(item, index) in menuList" :key="index" class="menu-item" @click="handleMenuClick(item)">
- <image class="menu-icon" src="/static/images/profile/7.png" mode="aspectFit"></image>
- <text class="menu-title">修改密码</text>
- <text class="menu-arrow">›</text>
- </view>
- </view> -->
- <!-- 退出 -->
- <view class="logout-wrapper">
- <text class="logout-btn" @click="handleLogout">退出</text>
- </view>
- </scroll-view>
- </view>
- </template>
- <script setup lang="uts">
- import { ref, onMounted } from 'vue'
- import { getUserInfo, getStoreIsKey } from '../../utils/storage'
- import { logout as logoutApi } from '../../api/auth/logout'
- import { useAuth } from '../../composables/useAuth'
- import { encryptAES, decryptAES } from '../../utils/crypto'
- import { getIsKey } from '../../api/auth/login'
- import { getConfigKey } from '../../api/system/config.uts'
- import { getBaseUrl } from '../../utils/request'
-
- // @ts-ignore
- import manifest from '@/manifest.json'
- // 用户信息
- const userName = ref<string>('')
- const userPhone = ref<string>('')
- const userDept = ref<string>('')
- const userRole = ref<string>('')
- const isNewVersion = ref<boolean>(false)
- const nickName = ref<string>('')
-
- // 版本信息
- const manifestVersion = manifest.versionName as string | null
- const version = ref<string>(manifestVersion != null ? manifestVersion : '1.0.0')
-
- // 认证管理
- const auth = useAuth()
- const clearAuth = auth.logout
- const getCurrentAccessToken = auth.getCurrentAccessToken
- // 菜单列表
- type MenuItem = {
- id: number
- title: string
- icon: string
- path?: string
- action?: string
- }
- const menuList = ref<MenuItem[]>([
- {
- id: 1,
- title: '修改密码',
- icon: '/static/images/profile/7.png',
- path: '/pages/profile/password/index'
- },
- {
- id: 2,
- title: '关于版本',
- icon: '/static/images/profile/5.png',
- action: 'version'
- },
- {
- id: 3,
- title: '关于我们',
- icon: '/static/images/profile/6.png',
- path: '/pages/profile/about/index'
- },
- {
- id: 4,
- title: '通用设置',
- icon: '/static/images/profile/8.png',
- path: '/pages/profile/settings/index'
- }
- ])
- // 通讯录点击
- const handleContactClick = (): void => {
- uni.showToast({
- title: '功能开发中',
- icon: 'none'
- })
- }
- const compareVersion = (newVersion: string, currentVersion: string): boolean => {
- const newVer = newVersion.split('.').map(item => parseInt(item))
- const currentVer = currentVersion.split('.').map(item => parseInt(item))
-
- const maxLength = Math.max(newVer.length, currentVer.length)
-
- for (let i = 0; i < maxLength; i++) {
- const newNum = i < newVer.length ? newVer[i] : 0
- const currentNum = i < currentVer.length ? currentVer[i] : 0
-
- if (newNum > currentNum) {
- return true
- } else if (newNum < currentNum) {
- return false
- }
- }
- return false
- }
-
- const checkVersion = async (): Promise<void> => {
- const versionJSON = await getConfigKey("gxt.android.version") as UTSJSONObject
- const versionServer = versionJSON['msg'] as string
- const hasNewVersion = compareVersion(versionServer, version.value) // true
- console.log("versionServer:"+versionServer)
- console.log("hasNewVersion:"+hasNewVersion)
- if(hasNewVersion){
- isNewVersion.value = true
- }
- }
- const handlePassword = (): void =>{
- uni.navigateTo({
- url:"/pages/profile/password/index",
- fail: (err: any) => {
- uni.showToast({
- title: '功能开发中',
- icon: 'none'
- })
- }
- })
- }
- // 菜单点击
- const handleMenuClick = (item: MenuItem): void => {
- if (item.action == 'version') {
- uni.showModal({
- title: '版本信息',
- content: `当前版本:v${version.value}`,
- showCancel: false
- })
- return
- }
- if (item.path != null && item.path.length > 0) {
- uni.navigateTo({
- url: item.path,
- fail: (err: any) => {
- uni.showToast({
- title: '功能开发中',
- icon: 'none'
- })
- }
- })
- }
- }
- // 执行退出登录(必须在 handleLogout 之前定义)
- const doLogout = async (): Promise<void> => {
- try {
- await logoutApi()
- } catch (e: any) {
- console.log('退出登录接口调用失败', e)
- } finally {
- uni.setStorageSync("login_key", "0")
- clearAuth()
- }
- }
- // 退出登录
- const handleLogout = (): void => {
- uni.showModal({
- title: '提示',
- content: '确定要退出登录吗?',
- success: (res) => {
- // 提取属性(any 类型不能直接访问属性)
- const confirm = res.confirm as boolean
- if (confirm) {
- // 使用异步函数包装
- doLogout()
- }
- }
- })
- }
- // 安装APK的单独函数
- const installApkFile = (filePath: string): void => {
- uni.installApk({
- filePath: filePath,
- success: () => {
- console.log('安装成功');
- uni.showToast({
- title: '安装成功',
- icon: 'success'
- });
- },
- fail: (error) => {
- console.error('安装失败:', error);
- uni.showToast({
- title: '安装失败',
- icon: 'none'
- });
- },
- complete: (res) => {
- console.log('安装完成:', res);
- }
- });
- }
-
-
-
- const installApkWithProgress = (): void => {
- // #ifdef APP-ANDROID
- // 显示下载进度
- uni.showLoading({
- title: '下载中...',
- mask: true
- });
- let donwloadUrl = '';
- donwloadUrl = getBaseUrl() + '/profile/app/gxt-release.apk'
-
- // 下载APK
- const downloadTask = uni.downloadFile({
- url: donwloadUrl,
- filePath: `${uni.env.USER_DATA_PATH}/${Date.now()}_test.apk`, // 使用时间戳防止重名
- success: (downloadRes) => {
- uni.hideLoading();
- if (downloadRes.statusCode == 200) {
- // 确认安装
- uni.showModal({
- title: '安装提示',
- content: '下载完成,是否立即安装?',
- success: (modalRes) => {
- if (modalRes.confirm) {
- installApkFile(downloadRes.tempFilePath);
- }
- }
- });
- } else {
- uni.showToast({
- title: '下载失败',
- icon: 'error'
- });
- }
- },
- fail: (error) => {
- uni.hideLoading();
- uni.showToast({
- title: '下载失败',
- icon: 'none'
- });
- console.error('下载失败:', error);
- }
- });
-
- // 监听下载进度
- downloadTask.onProgressUpdate((res) => {
- console.log('下载进度:', res.progress + '%');
- // 如果需要,可以更新UI显示进度
- uni.showLoading({
- title: `下载中...`,
- mask: true
- });
- });
- // #endif
- // #ifdef APP-HARMONY
- uni.showToast({
- title: '请登录PC端,扫描二维码下载并安装',
- icon: 'none'
- });
- // #endif
- // #ifdef APP-IOS
- uni.showToast({
- title: '请登录PC端,扫描二维码下载并安装',
- icon: 'none'
- });
- // #endif
- }
-
- // 菜单点击
- const handleVersionClick = (): void => {
- installApkWithProgress();
- }
-
- // 初始化
- onMounted(() => {
- checkVersion();
- const userInfo = getUserInfo()
- if (userInfo != null) {
- const nickNameRaw = userInfo['nickName'] as string | null
- const phone = userInfo['phone'] as string | null
- const userNameRaw = userInfo['userName'] as string | null
-
- const isKey = getStoreIsKey();
- if(isKey == "1"){
- userName.value = decryptAES(userNameRaw ?? '')
- nickName.value = decryptAES(nickNameRaw ?? '')
- if (phone != null && phone.length > 0) {
- userPhone.value = decryptAES(phone ?? '')
- }
- }else{
- userName.value = userNameRaw ?? ''
- nickName.value = nickNameRaw ?? ''
- if (phone != null && phone.length > 0) {
- userPhone.value = phone
- }
- }
-
- const deptName = userInfo['deptName'] as string | null
- if (deptName != null && deptName.length > 0) {
- userDept.value = deptName
- }
-
- const roleNames = userInfo['roleNames'] as string | null
- if (roleNames != null && roleNames.length > 0) {
- userRole.value = roleNames
- }
- }
- })
- </script>
- <style lang="scss">
- .page-container {
- position: relative;
- flex: 1;
- background: #f5f8fb;
- padding-top: env(safe-area-inset-top);
- }
- .bg-image {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- z-index: 0;
- }
- .page-content {
- position: relative;
- flex: 1;
- padding-bottom: 100rpx;
- z-index: 1;
- }
- .header {
- padding: 80rpx 30rpx 40rpx;
- flex-direction: row;
- align-items: center;
- .avatar {
- width: 120rpx;
- height: 120rpx;
- border: 1rpx solid #ccc;
- border-radius: 60rpx;
- background-color: #fff;
- margin-right: 30rpx;
- }
- .user-name {
- font-size: 40rpx;
- color: #ffffff;
- font-weight: bold;
- }
- }
- .info-cards {
- padding: 0 30rpx;
- flex-direction: row;
- justify-content: space-between;
- margin-bottom: 30rpx;
- .info-card {
- width: 330rpx;
- background-color: #ffffff;
- border-radius: 24rpx;
- padding: 30rpx 24rpx;
-
- /* #ifndef APP-HARMONY */
- box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
- /* #endif */
- .card-icon {
- width: 48rpx;
- height: 48rpx;
- margin-bottom: 16rpx;
- }
- .card-label {
- font-size: 26rpx;
- color: #666666;
- margin-bottom: 12rpx;
- }
- .card-value {
- font-size: 32rpx;
- color: #333333;
- font-weight: bold;
- }
- }
- }
- .contact-item {
- margin: 0 30rpx 30rpx;
- padding: 30rpx;
- background-color: #ffffff;
- border-radius: 24rpx;
- flex-direction: row;
- align-items: center;
-
- /* #ifndef APP-HARMONY */
- box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
- /* #endif */
- .contact-icon {
- width: 48rpx;
- height: 48rpx;
- margin-right: 24rpx;
- }
- .contact-text {
- flex: 1;
- font-size: 32rpx;
- color: #333333;
- }
- .contact-arrow {
- font-size: 48rpx;
- color: #cccccc;
- line-height: 48rpx;
- }
- }
- .menu-section {
- margin: 0 30rpx 30rpx;
- background-color: #ffffff;
- border-radius: 24rpx;
- overflow: hidden;
-
- /* #ifndef APP-HARMONY */
- box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
- /* #endif */
- .menu-item {
- flex-direction: row;
- align-items: center;
- padding: 30rpx;
- border-bottom: 1rpx solid #f0f0f0;
- &:last-child {
- border-bottom: none;
- }
- .menu-icon {
- width: 48rpx;
- height: 48rpx;
- margin-right: 24rpx;
- }
- .menu-title {
- flex: 1;
- font-size: 32rpx;
- color: #333333;
- }
-
- .menu-title-download {
- font-size: 30rpx;
- color: #5500ff;
- }
- .menu-arrow {
- font-size: 48rpx;
- color: #cccccc;
- line-height: 48rpx;
- }
- }
- }
- .logout-wrapper {
- margin: 0 30rpx 30rpx;
- background-color: #ffffff;
- border-radius: 24rpx;
- overflow: hidden;
- align-items: center;
- justify-content: center;
- height: 100rpx;
-
- /* #ifndef APP-HARMONY */
- box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
- /* #endif */
- .logout-btn {
- font-size: 32rpx;
- color: #666666;
- padding: 20rpx 0;
- }
- }
- </style>
|