record.vue 11 KB

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