record.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <view class="report_content">
  3. <view class="header">
  4. <view class="header_content">
  5. <view class="title">本次{{ type == "exam" ? "测评" : "学习" }}概览</view>
  6. <view class="content">
  7. <view class="content_row">
  8. <view class="main">{{ type == "exam" ? formatTime(reportInfo.exam_time) : formatTime(reportInfo.video_lasttime - reportInfo.video_inittime) }}</view>
  9. <view class="tip">学习时长</view>
  10. </view>
  11. <view class="content_row">
  12. <view class="main">{{ reportInfo.isanswer_total + "/" + reportInfo.answer_total }}</view>
  13. <view class="tip">答对题目</view>
  14. </view>
  15. <view class="content_row">
  16. <view class="main">{{ reportInfo.get_score }}</view>
  17. <view class="tip">获得积分</view>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="content">
  23. <view class="title">答题情况</view>
  24. <view class="content_list">
  25. <view class="conent_main" v-for="(item, index) in queston_list" :key="index">
  26. <view class="item_num">
  27. <view class="item_answer"><icon :type="item.is_answer == 0 ? 'cancel' : 'success'" size="20" /> &nbsp;第{{ index + 1 }}题</view>
  28. <view :style="item.get_score > 0 ? 'color:green' : 'color:red'">+{{ item.get_score }}&nbsp;积分</view>
  29. </view>
  30. <view class="item_title">{{ item.question_title }}</view>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="bottom_btn">
  35. <view class="submit_btn defult" v-if="reportInfo?.is_self" @click="showShareImage">生成分享图</view>
  36. <view class="submit_btn start_learn" v-if="!reportInfo?.is_self" @click="toLearn">开启我的学习计划</view>
  37. <view class="submit_btn" v-if="reportInfo?.is_self" @click="_continue">{{ type == "exam" ? "重新练习" : "继续课后评测" }}</view>
  38. </view>
  39. <uni-popup ref="filePathPopup" type="center" class="center_popup" >
  40. <view class="cover_black" :style="windowWidth">
  41. <image v-if="filePath" :src="filePath" mode="heightFix" class="file_path_image"></image>
  42. <view class="bottom_box">
  43. <view class="info_title">
  44. <view class="title_center">分享至</view>
  45. <button class="close_popup" @click.stop="closePupop"> X </button>
  46. </view>
  47. <button class="save_image_btn" @click.stop="saveImage">
  48. <image class="save_icon" src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/video/savepic.png" mode=""></image>
  49. <view class="save_text">保存图片</view>
  50. </button>
  51. </view>
  52. </view>
  53. </uni-popup>
  54. </view>
  55. </template>
  56. <script>
  57. export default {
  58. data() {
  59. return {
  60. reportInfo: {
  61. exam_time: 0,
  62. isanswer_total: 0,
  63. answer_total: 0,
  64. get_score: 0,
  65. is_self:1,
  66. },
  67. filePath:"",
  68. queston_list: [],
  69. record_id: null,
  70. type: null, // 确保 type 在 data 中定义
  71. windowWidth:{},
  72. };
  73. },
  74. onLoad(params) {
  75. console.log("params:", params); // 获取到query参数
  76. this.record_id = params.record_id;
  77. this.type = params.type;
  78. //分享按钮
  79. uni.showShareMenu({
  80. withShareTicket: true,
  81. menus: ["shareAppMessage", "shareTimeline"],
  82. });
  83. },
  84. onShow() {
  85. this._getRecord(this.type);
  86. this._getAnswerList(this.type);
  87. this.windowWidth = {height:uni.getWindowInfo().windowHeight+'px'};
  88. },
  89. onShareAppMessage(obj) {
  90. return {
  91. title: `999智控终端平台\n学习报告`,
  92. path: `/pages/video/record?type=${this.type}&record_id=${this.record_id}`,
  93. promise: new Promise((resolve, reject) => {
  94. this.$http.request(`api/${this.type}_report_share_image/get`, {course_id: this.reportInfo.course_id,record_id:this.record_id}).then((callback) => {
  95. let obj = {
  96. title: callback.data?.title,
  97. path: `/pages/video/record?type=${this.type}&record_id=${this.record_id}`,
  98. };
  99. if (callback.data?.image_url !== "") {
  100. obj.imageUrl = callback.data.image_url;
  101. }
  102. resolve(obj);
  103. });
  104. }),
  105. };
  106. },
  107. methods: {
  108. toLearn(){
  109. if( !this.reportInfo?.course_id ) {
  110. uni.showToast({
  111. icon:"none",
  112. title:"无对应课程ID",
  113. })
  114. return ;
  115. }
  116. uni.redirectTo({
  117. url: `/pages/video/detail?id=${this.reportInfo.course_id}`,
  118. });
  119. },
  120. showShareImage(){
  121. this.$http.request(`api/${this.type}_report_share_image/get_after`, {course_id: this.reportInfo.course_id,record_id:this.record_id,scene:`type=${this.type}&record_id=${this.record_id}`}).then((callback) => {
  122. if( callback.code == 'success'){
  123. // 分离base64中的数据部分
  124. const imgSrc = callback.data?.base64_image; // 假设这是你的base64字符串,例如:"data:image/png;base64,iVBORw0K..."
  125. const imgFormat = imgSrc.split(',')[1]; // 获取base64编码的图片数据部分
  126. const fileExt = imgSrc.split(';')[0].split('/')[1]; // 获取图片格式,例如:jpeg, png等
  127. const filePath = `${uni.env.USER_DATA_PATH}/${Date.now()}.${fileExt}`; // 临时文件路径,使用用户数据路径确保有权限写入
  128. // 使用uni.getFileSystemManager()将base64转换为文件并保存到相册
  129. const fs = uni.getFileSystemManager();
  130. fs.writeFile({
  131. filePath: filePath,
  132. data: imgFormat, // 直接写入base64编码的数据部分,不需要转换ArrayBuffer
  133. encoding: 'base64', // 指定编码为base64
  134. success: () => {
  135. this.filePath = filePath
  136. // 显示
  137. this.$refs.filePathPopup.open("center");
  138. },
  139. fail: function (err) {
  140. console.log('文件写入失败', err);
  141. uni.showToast({ title: '文件写入失败', icon: 'none' });
  142. }
  143. });
  144. }
  145. });
  146. },
  147. saveImage(){
  148. if( this.filePath ){
  149. uni.saveImageToPhotosAlbum({
  150. filePath: this.filePath,
  151. success:()=>{
  152. // 关闭结果
  153. this.$refs.filePathPopup.close();
  154. uni.showToast({ title: '保存成功', icon: 'success' });
  155. },
  156. fail:(err)=> {
  157. uni.showToast({ title: '保存失败', icon: 'none' });
  158. }
  159. });
  160. }
  161. },
  162. closePupop(){
  163. this.$refs.filePathPopup.close();
  164. },
  165. _backList() {
  166. uni.redirectTo({
  167. url: `/pages/video/index`,
  168. });
  169. },
  170. _continue() {
  171. uni.redirectTo({
  172. url: `/pages/video/exam?id=${this.reportInfo.course_id}`,
  173. });
  174. },
  175. _getRecord(type) {
  176. this.$http
  177. .request(`api/video_${type}_record/get_report`, {
  178. record_id: this.record_id,
  179. })
  180. .then((re) => {
  181. if (re.code == "success") {
  182. console.log(re.data);
  183. this.reportInfo = re.data;
  184. }
  185. });
  186. },
  187. _getAnswerList(type) {
  188. this.$http
  189. .request(`api/video_${type}_answer/get_list`, {
  190. record_id: this.record_id,
  191. })
  192. .then((re) => {
  193. if (re.code == "success") {
  194. console.log(re.data);
  195. this.queston_list = re.data;
  196. }
  197. });
  198. },
  199. formatTime(seconds) {
  200. const minutes = Math.floor(seconds / 60);
  201. const remainingSeconds = seconds % 60;
  202. return `${String(minutes).padStart(2, "0")}:${String(remainingSeconds).padStart(2, "0")}`;
  203. },
  204. },
  205. };
  206. </script>
  207. <style lang="less" scoped>
  208. .report_content {
  209. .header {
  210. width: 100vw;
  211. padding: 36rpx;
  212. box-sizing: border-box;
  213. .header_content {
  214. height: 360rpx;
  215. width: 100%;
  216. background: linear-gradient(to bottom right, #6765f1, #a556f7);
  217. border-radius: 20rpx;
  218. color: #fff;
  219. padding: 36rpx;
  220. box-sizing: border-box;
  221. .content {
  222. height: calc(100% - 55rpx);
  223. display: flex;
  224. align-items: center;
  225. justify-content: space-between;
  226. .content_row {
  227. display: flex;
  228. flex-direction: column;
  229. align-items: center;
  230. .main {
  231. font-size: 52rpx;
  232. font-weight: bold;
  233. margin-bottom: 20rpx;
  234. }
  235. .tip {
  236. color: #bba6ff;
  237. font-size: 28rpx;
  238. }
  239. }
  240. }
  241. }
  242. }
  243. > .content {
  244. width: 100vw;
  245. padding: 36rpx;
  246. box-sizing: border-box;
  247. > .title {
  248. font-size: 32rpx;
  249. font-weight: bold;
  250. margin-bottom: 36rpx;
  251. }
  252. > .content_list {
  253. width: 100%;
  254. height: calc(100vh - 750rpx);
  255. overflow: auto;
  256. box-sizing: border-box;
  257. display: flex;
  258. flex-direction: column;
  259. gap: 20rpx;
  260. .conent_main {
  261. border: 1px solid #ddd;
  262. box-shadow: 0 2px 4px 0 rgba(204, 204, 204, 0.5); /* 添加背景阴影 */
  263. width: 100%;
  264. padding: 20rpx;
  265. box-sizing: border-box;
  266. border-radius: 6rpx;
  267. display: flex;
  268. flex-direction: column;
  269. gap: 20rpx;
  270. .item_num {
  271. display: flex;
  272. justify-content: space-between;
  273. align-items: center;
  274. }
  275. .item_answer {
  276. display: flex;
  277. align-items: center;
  278. }
  279. }
  280. }
  281. }
  282. .bottom_btn {
  283. position: fixed;
  284. bottom: 0;
  285. left: 0;
  286. width: 100%;
  287. height: 150rpx;
  288. border-top: 4rpx solid #ddd;
  289. display: flex;
  290. align-items: center;
  291. justify-content: space-between;
  292. padding: 0 40rpx;
  293. box-sizing: border-box;
  294. .answer_info {
  295. display: flex;
  296. align-items: baseline;
  297. }
  298. .submit_btn {
  299. background-color: #5045e6;
  300. color: #fff;
  301. font-size: 28rpx;
  302. width: 45%;
  303. height: 80rpx;
  304. line-height: 80rpx;
  305. border-radius: 8rpx;
  306. box-shadow: 2rpx 2rpx 8rpx rgba(0, 0, 0, 0.1);
  307. text-align: center;
  308. &.defult {
  309. background-color: #fff;
  310. color: #333;
  311. }
  312. }
  313. .submit_btn.start_learn{
  314. width: 90%;
  315. margin: 0rpx auto;
  316. }
  317. }
  318. }
  319. .center_popup{
  320. .cover_black{
  321. display: block;
  322. width: 750rpx;
  323. position: relative;
  324. padding-top: 120rpx;
  325. background-color: rgba(0, 0, 0, 0.9);
  326. .file_path_image{
  327. top: 50%;
  328. left: 50%;
  329. width: 622rpx;
  330. height: 892rpx;
  331. display: block;
  332. position: absolute;
  333. margin-top: -560rpx;
  334. margin-left: -311rpx;
  335. }
  336. .bottom_box{
  337. left: 0rpx;
  338. bottom: 0rpx;
  339. width: 750rpx;
  340. height: 300rpx;
  341. position: absolute;
  342. background-color: #FFFFFF;
  343. border-top-left-radius: 20rpx;
  344. border-top-right-radius: 20rpx;
  345. .info_title{
  346. display: block;
  347. border: none;
  348. width: 750rpx;
  349. height: 60rpx;
  350. line-height: 60rpx;
  351. font-size: 28rpx;
  352. text-align: center;
  353. position: relative;
  354. .title_center{
  355. display: block;
  356. border: none;
  357. width: 120rpx;
  358. height: 60rpx;
  359. line-height: 60rpx;
  360. font-size: 28rpx;
  361. margin: 0rpx auto;
  362. text-align: center;
  363. }
  364. .close_popup{
  365. top: 0rpx;
  366. right: 0rpx;
  367. border: none;
  368. width: 60rpx;
  369. height: 60rpx;
  370. font-size: 32rpx;
  371. padding: 0rpx 0rpx;
  372. line-height: 60rpx;
  373. position: absolute;
  374. background-color: transparent;
  375. }
  376. .close_popup::after{
  377. border: none;
  378. background-color: transparent;
  379. }
  380. }
  381. .save_image_btn{
  382. display: block;
  383. border: none;
  384. width: 300rpx;
  385. height: 120rpx;
  386. margin: 0rpx auto;
  387. overflow: hidden;
  388. margin-top: 40rpx;
  389. padding: 0rpx 0rpx;
  390. text-align: center;
  391. line-height: 80rpx;
  392. vertical-align: middle;
  393. background-color: transparent;
  394. .save_icon{
  395. float: left;
  396. width: 80rpx;
  397. height: 80rpx;
  398. }
  399. .save_text{
  400. float: left;
  401. width: 180rpx;
  402. height: 80rpx;
  403. font-size: 32rpx;
  404. }
  405. }
  406. .save_image_btn::after{
  407. border: none;
  408. background-color: transparent;
  409. }
  410. }
  411. }
  412. }
  413. </style>