CpdmMessage.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <script lang="ts" setup>
  2. import { ref, defineExpose } from 'vue'
  3. import { useRouter } from 'vue-router'
  4. import { userInfoStore } from '@/stores'
  5. import { ElMessage } from 'element-plus';
  6. import { pubMsgApi } from '@/api/plan';
  7. const router = useRouter()
  8. //获取缓存用户信息
  9. const userInfo = userInfoStore();
  10. //留言显示的标志
  11. const pub_visible = ref<boolean>(false)
  12. //留言的内容
  13. const des_input = ref<string>('')
  14. //用户的姓名
  15. const userName = ref<string>('')
  16. //用户的编号
  17. const userNo = ref<string>('');
  18. //用户的性别
  19. const userSex = ref<string>('')
  20. //防止重复点
  21. const isLock = ref<boolean>(false)
  22. const open = () => {
  23. userName.value = userInfo.userInfo.userName;
  24. userNo.value = userInfo.userInfo.userNo;
  25. userSex.value = userInfo.userInfo.gender;
  26. pub_visible.value = true
  27. }
  28. //点击进行发布信息
  29. const pubMsg = async () => {
  30. //判断用户是否登陆了
  31. if (!userInfo.token) {
  32. ElMessage({
  33. message: '尚未登录',
  34. type: 'warning'
  35. })
  36. return
  37. }
  38. if (des_input.value == '') {
  39. ElMessage({
  40. message: '留言不能为空',
  41. type: 'warning'
  42. })
  43. return
  44. }
  45. if (isLock.value) {
  46. return
  47. }
  48. isLock.value = true
  49. let params = {
  50. userNo: userNo.value,
  51. userName: userName.value,
  52. commentContent: des_input.value
  53. }
  54. let res: any = await pubMsgApi(params)
  55. if (res.code == 200) {
  56. ElMessage({
  57. message: '留言成功',
  58. type: 'success'
  59. })
  60. des_input.value = ''
  61. isLock.value = false
  62. pub_visible.value = false
  63. //开始跳转到页面测试记录页面
  64. // router.push({ name: 'popularizationScience' })
  65. router.push({ name: 'testRecord' })
  66. //修改需求后看不见更多测试了----需要跳转到测试结果页面
  67. } else {
  68. ElMessage({
  69. message: res.msg,
  70. type: 'error'
  71. })
  72. }
  73. //调用新增留言的方法
  74. }
  75. //点击关闭弹出框
  76. const colseMessage = () => {
  77. // router.push({ name: 'popularizationScience' })
  78. router.push({ name: 'testRecord' })
  79. }
  80. defineExpose({ open })
  81. </script>
  82. <template>
  83. <el-dialog v-model="pub_visible" :show-close="true" @closed="colseMessage" width="60%"
  84. style="border-radius: 5px; ">
  85. <template #header="{ close, titleId, titleClass }">
  86. <div class="my-header">
  87. <div class="msg_dig">
  88. <img width="40px" v-show="userSex == '1'" src="../assets/kepu/man.png" />
  89. <img width="40px" v-show="userSex == '0'" src="../assets/kepu/woman.png" />
  90. <div style="margin-left:20px">{{ userName }}</div>
  91. </div>
  92. <!-- <textarea ref="des_input" rows="5" cols="43" placeholder="写下你珍贵的留言" /> -->
  93. <el-input type="textarea" style="margin-top: 20px;" :autosize="{ minRows: 6 }" placeholder="写下你珍贵的留言"
  94. v-model="des_input">
  95. </el-input>
  96. <div class="home_mid_plan_button">
  97. <div class="pub_button" @click="pubMsg"> 发布留言
  98. </div>
  99. </div>
  100. </div>
  101. </template>
  102. </el-dialog>
  103. </template>
  104. <style lang="scss" scoped>
  105. :deep(.el-textarea__inner) {
  106. background-color: #F7F7F7 !important;
  107. border: none !important;
  108. border-radius: 20px;
  109. border: none !important;
  110. box-shadow: none !important;
  111. }
  112. .msg_dig {
  113. display: flex;
  114. flex-direction: row;
  115. align-items: center;
  116. }
  117. .home_mid_plan_button {
  118. width: 100%;
  119. display: flex;
  120. flex-direction: row;
  121. justify-content: end;
  122. margin-top: 40px;
  123. // text-align: right;
  124. .pub_button {
  125. cursor: pointer;
  126. // width: 100px;
  127. border-radius: 4px;
  128. border: 3px solid #48D68E;
  129. color: #ffffff;
  130. background-color: #3B3B3B;
  131. padding: 8px 30px;
  132. cursor: pointer;
  133. display: flex;
  134. align-items: center;
  135. }
  136. }
  137. </style>