teacher-profile.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <!-- 退出切换按钮 -->
  4. <view class="switch-out-btn" @click="switchToParent">
  5. <text>🔄 切换本人端</text>
  6. </view>
  7. <view class="user-card">
  8. <view class="avatar">👤</view>
  9. <view class="user-info">
  10. <view class="nickname">{{ nickname || '未设置昵称' }}</view>
  11. <view class="role">成长规划师</view>
  12. <view class="status-tag" :class="teacherStatus">{{ statusText }}</view>
  13. </view>
  14. <button class="btn-edit" @click="goToEditInfo">编辑资料</button>
  15. </view>
  16. <!-- 功能菜单 -->
  17. <view class="menu-list">
  18. <view class="menu-item" @click="goToEditInfo">
  19. <text>📝 修改个人资料</text>
  20. <text class="arrow">›</text>
  21. </view>
  22. <view class="menu-item" v-if="teacherStatus !== 'approved'" @click="showPendingInfo">
  23. <text>📋 查看申请进度</text>
  24. <text class="arrow">›</text>
  25. </view>
  26. <view class="menu-item" @click="goToGrowth">
  27. <text>📊 我的成长记录</text>
  28. <text class="arrow">›</text>
  29. </view>
  30. <view class="menu-item" @click="goToCertification">
  31. <text>🎓 培训认证中心</text>
  32. <text class="arrow">›</text>
  33. </view>
  34. <!-- 聊天功能已隐藏(临时): <view class="menu-item" @click="goToMessages">
  35. <text>💬 消息中心</text>
  36. <text class="arrow">›</text>
  37. </view> -->
  38. <view class="menu-item" @click="goToInviteParent">
  39. <text>📮 邀请家人</text>
  40. <text class="arrow">›</text>
  41. </view>
  42. <view class="menu-item" @click="showPasswordModal = true">
  43. <text>🔐 设置密码</text>
  44. <text class="arrow">›</text>
  45. </view>
  46. <view class="menu-item" @click="logout">
  47. <text>🚪 退出登录</text>
  48. <text class="arrow">›</text>
  49. </view>
  50. </view>
  51. <!-- 密码设置弹窗 -->
  52. <view class="modal-mask" v-if="showPasswordModal" @click="showPasswordModal = false">
  53. <view class="modal" @click.stop>
  54. <view class="modal-title">设置密码</view>
  55. <view class="form-item">
  56. <input v-model="newPassword" type="number" password placeholder="输入6位密码" maxlength="6" />
  57. </view>
  58. <view class="form-item">
  59. <input v-model="confirmPassword" type="number" password placeholder="确认密码" maxlength="6" />
  60. </view>
  61. <view class="modal-btns">
  62. <button @click="showPasswordModal = false">取消</button>
  63. <button class="btn-primary" @click="savePassword">确定</button>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="bottom-space"></view>
  68. </view>
  69. </template>
  70. <script>
  71. import { switchRole, generateParentInvite } from '../../utils/api.js'
  72. import fontScaleMixin from '@/mixins/font-scale.js'
  73. export default {
  74. mixins: [fontScaleMixin],
  75. data() {
  76. return {
  77. nickname: '',
  78. showPasswordModal: false,
  79. newPassword: '',
  80. confirmPassword: ''
  81. }
  82. },
  83. computed: {
  84. teacherStatus() {
  85. return uni.getStorageSync('teacherStatus') || 'pending'
  86. },
  87. statusText() {
  88. const map = { pending: '审核中', approved: '已通过', rejected: '已拒绝' }
  89. return map[this.teacherStatus] || this.teacherStatus
  90. }
  91. },
  92. onLoad() {
  93. var _userInfo = uni.getStorageSync('userInfo')
  94. this.nickname = (_userInfo && _userInfo.nickname) || ''
  95. },
  96. onShow() {
  97. var _userInfo = uni.getStorageSync('userInfo')
  98. this.nickname = (_userInfo && _userInfo.nickname) || ''
  99. },
  100. methods: {
  101. async switchToParent() {
  102. try {
  103. const result = await switchRole('parent')
  104. if (result.code === 200 && result.data) {
  105. const data = result.data
  106. uni.setStorageSync('token', data.token)
  107. uni.setStorageSync('role', data.role)
  108. uni.setStorageSync('currentRole', 'parent')
  109. uni.setStorageSync('isSwitchedChild', false)
  110. uni.setStorageSync('isSwitchedTeacher', false)
  111. uni.$emit('switchRole')
  112. uni.reLaunch({ url: '/pages/index-home/index' })
  113. }
  114. } catch (e) {
  115. uni.showToast({ title: e.message || '切换失败', icon: 'none' })
  116. }
  117. },
  118. goToEditInfo() {
  119. uni.navigateTo({ url: '/pages/user-edit/user-edit' })
  120. },
  121. goToGrowth() {
  122. uni.reLaunch({ url: '/pages/growth-main/index' })
  123. },
  124. goToCertification() {
  125. uni.navigateTo({ url: '/pages/teacher/certification-center' })
  126. },
  127. goToMessages() {
  128. uni.navigateTo({ url: '/pages/teacher/messages' })
  129. },
  130. async goToInviteParent() {
  131. try {
  132. uni.showLoading({ title: '生成邀请码中...' })
  133. const result = await generateParentInvite()
  134. uni.hideLoading()
  135. if (result.code === 200) {
  136. const { code, type, refId } = result.data
  137. const inviteUrl = `pages/index/index?inviteCode=${code}&type=${type}`
  138. uni.showModal({
  139. title: '邀请家人',
  140. content: `邀请码:${code}\n\n请复制并分享给家人,家人打开小程序后自动识别`,
  141. confirmText: '复制链接',
  142. cancelText: '关闭',
  143. success: (res) => {
  144. if (res.confirm) {
  145. uni.setClipboardData({
  146. data: inviteUrl,
  147. success: () => {
  148. uni.showToast({ title: '已复制', icon: 'success' })
  149. }
  150. })
  151. }
  152. }
  153. })
  154. }
  155. } catch (e) {
  156. uni.hideLoading()
  157. uni.showToast({ title: e.message || '生成失败', icon: 'none' })
  158. }
  159. },
  160. showPendingInfo() {
  161. const status = this.teacherStatus
  162. let content = ''
  163. if (status === 'pending') {
  164. content = '您的成长规划师申请正在审核中,通常1-3个工作日内完成。请耐心等待管理员审批。'
  165. } else if (status === 'rejected') {
  166. const reason = uni.getStorageSync('teacherRejectReason')
  167. content = reason ? ('您的申请未通过审核。拒绝原因:' + reason + '。您可以修改资料后重新申请。') : '您的申请暂未通过审核,您可以修改资料后重新申请。'
  168. }
  169. uni.showModal({
  170. title: '申请状态',
  171. content: content,
  172. confirmText: status === 'rejected' ? '重新申请' : '我知道了',
  173. showCancel: status === 'rejected',
  174. cancelText: '关闭',
  175. success: (res) => {
  176. if (res.confirm && status === 'rejected') {
  177. uni.navigateTo({ url: '/pages/profile/service-role-apply' })
  178. }
  179. }
  180. })
  181. },
  182. async savePassword() {
  183. if (!this.newPassword || this.newPassword.length !== 6) {
  184. uni.showToast({ title: '请输入6位密码', icon: 'none' })
  185. return
  186. }
  187. if (this.newPassword !== this.confirmPassword) {
  188. uni.showToast({ title: '两次密码不一致', icon: 'none' })
  189. return
  190. }
  191. uni.showToast({ title: '密码设置成功', icon: 'success' })
  192. this.showPasswordModal = false
  193. this.newPassword = ''
  194. this.confirmPassword = ''
  195. },
  196. logout() {
  197. uni.showModal({
  198. title: '提示',
  199. content: '确定要退出登录吗?',
  200. success: (res) => {
  201. if (res.confirm) {
  202. uni.clearStorage()
  203. uni.reLaunch({ url: '/pages/login/login' })
  204. }
  205. }
  206. })
  207. }
  208. }
  209. }
  210. </script>
  211. <style scoped lang="scss">
  212. .container {
  213. padding: 24rpx;
  214. background: $tint-sky-ghost;
  215. min-height: 100vh;
  216. }
  217. .switch-out-btn {
  218. background: $app-surface;
  219. border-radius: 16rpx;
  220. padding: 20rpx;
  221. margin-bottom: 16rpx;
  222. text-align: center;
  223. font-size: calc(28rpx * var(--font-scale, 1));
  224. color: $status-info;
  225. }
  226. .switch-out-btn text {
  227. margin-right: 8rpx;
  228. }
  229. .user-card {
  230. background: $app-surface;
  231. border-radius: 16rpx;
  232. padding: 24rpx;
  233. margin-bottom: 24rpx;
  234. display: flex;
  235. align-items: center;
  236. }
  237. .avatar {
  238. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  239. margin-right: 20rpx;
  240. }
  241. .user-info {
  242. flex: 1;
  243. }
  244. .nickname {
  245. font-size: calc(32rpx * var(--font-scale, 1));
  246. font-weight: bold;
  247. color: $uni-text-color;
  248. }
  249. .role {
  250. font-size: calc(24rpx * var(--font-scale, 1));
  251. color: $uni-text-color-secondary;
  252. margin-top: 4rpx;
  253. }
  254. .status-tag {
  255. display: inline-block;
  256. font-size: calc(22rpx * var(--font-scale, 1));
  257. padding: 4rpx 12rpx;
  258. border-radius: 8rpx;
  259. margin-top: 8rpx;
  260. }
  261. .status-tag.pending { background: $status-warning-soft; color: $status-warning-deep; }
  262. .status-tag.approved { background: $status-success-tint; color: $status-success-deep; }
  263. .status-tag.rejected { background: $status-danger-tint-2; color: $status-danger-deep; }
  264. .btn-edit {
  265. background: $status-info;
  266. color: $app-surface;
  267. font-size: calc(24rpx * var(--font-scale, 1));
  268. padding: 8rpx 20rpx;
  269. border-radius: 8rpx;
  270. }
  271. .menu-list {
  272. background: $app-surface;
  273. border-radius: 16rpx;
  274. overflow: hidden;
  275. }
  276. .menu-item {
  277. display: flex;
  278. justify-content: space-between;
  279. align-items: center;
  280. padding: 28rpx 24rpx;
  281. border-bottom: 1rpx solid $facade-fill;
  282. font-size: calc(28rpx * var(--font-scale, 1));
  283. color: $facade-text-strong;
  284. }
  285. .menu-item:last-child {
  286. border-bottom: none;
  287. }
  288. .arrow {
  289. color: $facade-text-ghost;
  290. font-size: calc(32rpx * var(--font-scale, 1));
  291. }
  292. .modal-mask {
  293. position: fixed;
  294. top: 0;
  295. left: 0;
  296. right: 0;
  297. bottom: 0;
  298. background: rgba(0, 0, 0, 0.5);
  299. display: flex;
  300. align-items: center;
  301. justify-content: center;
  302. z-index: 1000;
  303. }
  304. .modal {
  305. background: $app-surface;
  306. border-radius: 16rpx;
  307. padding: 32rpx;
  308. width: 560rpx;
  309. }
  310. .modal-title {
  311. font-size: calc(32rpx * var(--font-scale, 1));
  312. font-weight: bold;
  313. text-align: center;
  314. margin-bottom: 24rpx;
  315. }
  316. .form-item {
  317. margin-bottom: 20rpx;
  318. }
  319. .form-item input {
  320. border: 1rpx solid $facade-border-soft;
  321. border-radius: 8rpx;
  322. padding: 16rpx;
  323. font-size: calc(28rpx * var(--font-scale, 1));
  324. }
  325. .modal-btns {
  326. display: flex;
  327. gap: 20rpx;
  328. margin-top: 24rpx;
  329. }
  330. .modal-btns button {
  331. flex: 1;
  332. padding: 16rpx;
  333. border-radius: 8rpx;
  334. font-size: calc(28rpx * var(--font-scale, 1));
  335. background: $facade-fill-2;
  336. color: $facade-text-strong;
  337. }
  338. .modal-btns .btn-primary {
  339. background: $status-info;
  340. color: $app-surface;
  341. }
  342. .bottom-space {
  343. height: 140rpx;
  344. }
  345. </style>