questiondetails.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <view>
  3. <!-- pages/me.wxml -->
  4. <view class="container">
  5. <h1 class="title">{{ form.title }}</h1>
  6. <view class="wenzhangLy">
  7. <!-- 头像昵称 -->
  8. <view class="txTime">
  9. <image
  10. :src="initInfo.headImg == null || initInfo.headImg == '' ? initImgPath : loadImgSrcLocalhost(initInfo.headImg)"></image>
  11. <view class="time">
  12. <p>{{ initInfo.name == null || initInfo.name == '' ? initInfo.wechatName : initInfo.name }}</p>
  13. <span>{{ form.createTime }}</span>
  14. </view>
  15. </view>
  16. <!-- 积分 -->
  17. <span class="jf">
  18. {{ form.score }}
  19. <em class="iconfont icon-jifen"></em>
  20. </span>
  21. </view>
  22. <view class="wenzhangCont">
  23. <view v-html="form.text" class="rich-text"></view>
  24. <image :src="loadImgSrcLocalhost(path)" v-for="(path, index2) in form.paths" :key="index2"></image>
  25. </view>
  26. <view class="fengexian"></view>
  27. <!-- 分割线 -->
  28. <view class="pinglunTj">
  29. <span class="pinglunTitle">
  30. 回答
  31. <em>{{ form.answerList.length }}</em>
  32. </span>
  33. <view class="ck">
  34. <span>
  35. <em class="iconfont icon-chakan"></em>
  36. {{ form.browse }}
  37. </span>
  38. <span>
  39. <em class="iconfont icon-shoucang"></em>
  40. {{ form.collect }}
  41. </span>
  42. </view>
  43. </view>
  44. <ul class="pinglunList" id="pinglunList">
  45. <li v-for="(e,idx) in form.answerList" :key="idx" style="position: relative;">
  46. <!-- 头像昵称 -->
  47. <view class="txTime">
  48. <image :src="e.headImg == null || e.headImg == '' ? initImgPath : loadImgSrcLocalhost(e.headImg)"></image>
  49. <view class="time">
  50. <p>{{ e.name == null || e.name == '' ? e.wechatName : e.name }}</p>
  51. <span>{{ e.createTime }}</span>
  52. </view>
  53. </view>
  54. <!-- <div class="effectBox" :style="{ top: adoptTopSize + '%' }">精选答案</div> -->
  55. <div class="effectBix" :style="e.adopt == adoptIndex ? 'display:block' : 'display:none' ">采 纳</div>
  56. <text class="plListcont" style="z-index: 10;">{{ e.answer }}</text>
  57. <uploadImage/>
  58. <button v-show="!isAdopt" @click="adoptFunc(e.id)">采纳答案</button>
  59. </li>
  60. </ul>
  61. </view>
  62. <view class="fabiaoPl" :class="isCollection ? 'collect' : 'not-collect'" style="z-index: 100;">
  63. <view class="shuRu">
  64. <em class="iconfont icon-bianji"></em>
  65. <input placeholder="请输入内容,友好回答" v-model="anwserVal"/>
  66. </view>
  67. <em
  68. class="iconfont icon-shoucang"
  69. @click="collectionFunc(form.id)"
  70. >
  71. </em>
  72. <view class="fasong" @click="answerFunc(form.id,anwserVal)"><em class="iconfont icon-fasong"></em></view>
  73. </view>
  74. </view>
  75. </template>
  76. <script>
  77. import {
  78. getDetailById,
  79. getUserInfo,
  80. addCollect,
  81. addAnswer,
  82. adoptAnswer,
  83. selectCollect
  84. } from '@/api/asking/questiondetails.js';
  85. // pages/me.js
  86. export default {
  87. data() {
  88. return {
  89. initImgPath: 'https://sookajs.top:8888/profile/upload/moren.png',
  90. anwserVal: '',
  91. isCollection: false,
  92. isAdopt: false,
  93. adoptTopSize: '115',
  94. adoptIndex: 1,
  95. form: {},
  96. answer: {},
  97. initInfo: {},
  98. collect: {},
  99. };
  100. },
  101. methods: {
  102. // 评论回答
  103. answerFunc(id, answer) {
  104. this.answer.questionId = id
  105. this.answer.answer = answer
  106. this.answer.createBy = getApp().globalData.userId
  107. addAnswer(this.answer).then(res => {
  108. getUserInfo(getApp().globalData.userId).then((res) => {
  109. let userInfo = res.data;
  110. let newAnswer={
  111. adopt: null,
  112. answer: answer,
  113. createTime: new Date(),
  114. headImg: userInfo.headImg,
  115. name: userInfo.name,
  116. questionId: id,
  117. remark: null,
  118. score: null,
  119. updateBy: null,
  120. updateTime: null,
  121. version: null,
  122. wechatName: userInfo.wechatName
  123. }
  124. this.form.answerList.push(newAnswer);
  125. });
  126. })
  127. this.anwserVal = null
  128. },
  129. //采纳答案
  130. adoptFunc(id) {
  131. this.answer.id = id
  132. this.answer.createBy = getApp().globalData.userId
  133. this.answer.score = this.form.score
  134. adoptAnswer(this.answer).then(res => {
  135. })
  136. this.isAdopt = true
  137. this.form.answerList.forEach(v => {
  138. if (v.id == id) {
  139. v.adopt = 1
  140. }
  141. })
  142. },
  143. //是否收藏
  144. selectCollect(id) {
  145. this.collect.userId = getApp().globalData.userId;
  146. this.collect.questionId = id
  147. selectCollect(this.collect).then(res => {
  148. if (res.data.length != 0) {
  149. this.isCollection = true
  150. }
  151. })
  152. },
  153. // 标记喜欢
  154. collectionFunc(id) {
  155. this.collect.userId = getApp().globalData.userId;
  156. this.collect.questionId = id
  157. addCollect(this.collect).then(res => {
  158. })
  159. this.isCollection = !this.isCollection
  160. },
  161. //获取问题详情
  162. getDetailById(id) {
  163. this.form.id = id
  164. getDetailById(this.form).then(res => {
  165. res.data.answerList.forEach(v => {
  166. if (v.adopt == "1") {
  167. this.isAdopt = true
  168. }
  169. })
  170. let form = res.data
  171. form.text = this.imgReplace(form.text)
  172. console.log('form',form)
  173. this.form = form
  174. // this.form = res.data
  175. this.getUserInfoByUserId(this.form.createBy);//获取用户信息
  176. this.selectCollect(id);//是否收藏
  177. })
  178. },
  179. imgReplace (htmldoc) {
  180. // 正则匹配所有img标签
  181. // var regex0 = new RegExp("(i?)(\<img)([^\>]+\>)","gmi");
  182. // 正则匹配不含style="" 或 style='' 的img标签
  183. var reg1 = new RegExp("(i?)(\<img)(?!(.*?style=['\"](.*)['\"])[^\>]+\>)", 'gmi')
  184. // 给不含style="" 或 style='' 的img标签加上style=""
  185. htmldoc = htmldoc.replace(reg1, '$2 style=""$3')
  186. // 正则匹配含有style的img标签
  187. var reg2 = new RegExp("(i?)(\<img.*?style=['\"])([^\>]+\>)", 'gmi')
  188. // 在img标签的style里面增加css样式(这里增加的样式:display:block;max-width:100%;height:auto;border:5px solid red;)
  189. htmldoc = htmldoc.replace(reg2, '$2width:100%;$3')
  190. return htmldoc
  191. },
  192. //获取用户信息:用户名称:头像
  193. getUserInfoByUserId(userId) {
  194. getUserInfo(userId).then((res) => {
  195. this.initInfo = res.data;
  196. });
  197. },
  198. }
  199. /**
  200. * 生命周期函数--监听页面加载
  201. */,
  202. onLoad(options) {
  203. this.getDetailById(options.id)
  204. },
  205. /**
  206. * 生命周期函数--监听页面初次渲染完成
  207. */
  208. onReady(e) {
  209. },
  210. /**
  211. * 生命周期函数--监听页面显示
  212. */
  213. onShow() {
  214. },
  215. /**
  216. * 生命周期函数--监听页面隐藏
  217. */
  218. onHide() {
  219. },
  220. /**
  221. * 生命周期函数--监听页面卸载
  222. */
  223. onUnload() {
  224. },
  225. /**
  226. * 页面相关事件处理函数--监听用户下拉动作
  227. */
  228. onPullDownRefresh() {
  229. },
  230. /**
  231. * 页面上拉触底事件的处理函数
  232. */
  233. onReachBottom() {
  234. },
  235. /**
  236. * 用户点击右上角分享
  237. */
  238. onShareAppMessage() {
  239. },
  240. };
  241. </script>
  242. <style lang="scss" scoped>
  243. @import '@/pages/asking/questiondetails.css';
  244. .collect {
  245. .icon-shoucang:before {
  246. color: red;
  247. }
  248. }
  249. .not-collect {
  250. }
  251. .rich-text {
  252. overflow: hidden;
  253. }
  254. .rich-text p >img{
  255. width: 100%;
  256. }
  257. .effectBix {
  258. width: 56px;
  259. height: 56px;
  260. border-radius: 50px;
  261. font-family: 'Bebas Neue', cursive;
  262. background: linear-gradient(45deg, transparent 5%, #FF013C 5%);
  263. border: 0;
  264. color: #fff;
  265. text-align: center;
  266. line-height: 56px;
  267. outline: transparent;
  268. position: absolute;
  269. transform: rotate(-30deg);
  270. right: 3%;
  271. top: -5%;
  272. }
  273. .effectBox, .effectBox::after {
  274. width: 56px;
  275. height: 56px;
  276. border-radius: 50px;
  277. font-size: 16px;
  278. font-family: 'Bebas Neue', cursive;
  279. background: linear-gradient(45deg, transparent 5%, #FF013C 5%);
  280. border: 0;
  281. color: #fff;
  282. opacity: 1;
  283. letter-spacing: 3px;
  284. text-align: center;
  285. line-height: 56px;
  286. outline: transparent;
  287. position: relative;
  288. left: 78%;
  289. top: 113%;
  290. transform: rotate(-30deg);
  291. z-index: 1;
  292. }
  293. .effectBox::after {
  294. --slice-0: inset(50% 50% 50% 50%);
  295. --slice-1: inset(80% -6px 0 0);
  296. --slice-2: inset(50% -6px 30% 0);
  297. --slice-3: inset(10% -6px 85% 0);
  298. --slice-4: inset(40% -6px 43% 0);
  299. --slice-5: inset(80% -6px 5% 0);
  300. content: 'AVAILABLE NOW';
  301. display: block;
  302. position: absolute;
  303. top: 0;
  304. left: 0;
  305. right: 0;
  306. bottom: 0;
  307. background: linear-gradient(45deg, transparent 3%, #00E6F6 3%, #00E6F6 5%, #FF013C 5%);
  308. text-shadow: -3px -3px 0px #F8F005, 3px 3px 0px #00E6F6;
  309. clip-path: var(--slice-0);
  310. }
  311. .effectBox:hover::after {
  312. animation: 1s glitch;
  313. animation-timing-function: steps(2, end);
  314. }
  315. @keyframes glitch {
  316. 0% {
  317. clip-path: var(--slice-1);
  318. transform: translate(-20px, -10px);
  319. }
  320. 10% {
  321. clip-path: var(--slice-3);
  322. transform: translate(10px, 10px);
  323. }
  324. 20% {
  325. clip-path: var(--slice-1);
  326. transform: translate(-10px, 10px);
  327. }
  328. 30% {
  329. clip-path: var(--slice-3);
  330. transform: translate(0px, 5px);
  331. }
  332. 40% {
  333. clip-path: var(--slice-2);
  334. transform: translate(-5px, 0px);
  335. }
  336. 50% {
  337. clip-path: var(--slice-3);
  338. transform: translate(5px, 0px);
  339. }
  340. 60% {
  341. clip-path: var(--slice-4);
  342. transform: translate(5px, 10px);
  343. }
  344. 70% {
  345. clip-path: var(--slice-2);
  346. transform: translate(-10px, 10px);
  347. }
  348. 80% {
  349. clip-path: var(--slice-5);
  350. transform: translate(20px, -10px);
  351. }
  352. 90% {
  353. clip-path: var(--slice-1);
  354. transform: translate(-10px, 0px);
  355. }
  356. 100% {
  357. clip-path: var(--slice-1);
  358. transform: translate(0);
  359. }
  360. }
  361. </style>