teacher-profile.vue 9.2 KB

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