teacher-profile.vue 9.1 KB

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