img_process.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <template>
  2. <view class="content">
  3. <text v-if="process_show" class="title">x胸腔图病症识别器</text>
  4. <text v-else style="color: #666;">{{timeString}}</text>
  5. <view class="history">
  6. <image @click="$util.navigateTo('/pages/img_process/img_process_history/img_process_history')" src="@/static/img/history_bmi.png"></image>
  7. <p style="text-align: center;" class="head-text">历史</p>
  8. </view>
  9. <uv-gap height="10"></uv-gap>
  10. <view v-if="process_show" class="flex justify-center" style="align-items: center; padding: 20px;">
  11. <view class="flex justify-between align-center">
  12. <uv-upload
  13. @oversize="tip()"
  14. maxSize=1048576
  15. :compressed='false'
  16. :fileList="fileList1"
  17. name="1"
  18. :maxCount="1"
  19. @afterRead="afterRead"
  20. @delete="deletePic"
  21. :previewFullImage="true"
  22. width="100"
  23. height="100">
  24. </uv-upload>
  25. <image v-if="img_url" class="arrow" src="/static/img/右箭头.png" mode="widthFix" style="background-color: #fff;"></image>
  26. <image v-if="img_url" :src="img_url" mode="widthFix"></image>
  27. </view>
  28. </view>
  29. <uv-gap v-if="process_show" height="10"></uv-gap>
  30. <view v-if="process_show && !processed" class="flex justify-center">
  31. <uv-button @click="processImg" color="#1678ff" text="确定" customStyle="width:85vw" customTextStyle="font-weight: 1000;"></uv-button>
  32. </view>
  33. <uv-gap height="10"></uv-gap>
  34. <view v-if="resInfo">
  35. <view v-if="resInfo['code']">
  36. <h3 v-if="process_show" style="font-weight: 1000;color: #53c21d;">处理成功:</h3>
  37. <uv-gap height="5"></uv-gap>
  38. <view style="font-size: 16px;">
  39. <text style="color: #666;">识别结果:</text>
  40. <text style="color: #f56c6c;margin-right: 10px;" v-for="(diseaseValue, diseaseKey) in resInfo['data']['disease']" :key="diseaseKey">{{diseaseValue}}</text>
  41. </view>
  42. <uv-gap v-if="!process_show" height="20"></uv-gap>
  43. <uv-gap height="10"></uv-gap>
  44. <view class="diseaseItem" v-for="(diseaseValue, diseaseKey) in resInfo['data']['disease']" :key="diseaseKey">
  45. <text>{{diseaseValue}}:</text>
  46. <view>
  47. <text>饮食建议:</text>
  48. <view v-for="(dietValue, dietKey) in resInfo['data'][diseaseValue]['饮食建议']" :key="dietKey">
  49. <text>{{dietValue}}</text>
  50. </view>
  51. </view>
  52. <view>
  53. <text>锻炼建议:</text>
  54. <view v-for="(exerciseValue, exerciseKey) in resInfo['data'][diseaseValue]['锻炼建议']" :key="exerciseKey">
  55. <text>{{exerciseValue}}</text>
  56. </view>
  57. </view>
  58. <view>
  59. <text>睡眠建议:</text>
  60. <view v-for="(sleepValue, sleepKey) in resInfo['data'][diseaseValue]['睡眠建议']" :key="sleepKey">
  61. <text>{{sleepValue}}</text>
  62. </view>
  63. </view>
  64. <view>
  65. <text>用药建议:</text>
  66. <view v-for="(medicationValue, medicationKey) in resInfo['data'][diseaseValue]['用药建议']" :key="medicationKey">
  67. <text>{{medicationValue}}</text>
  68. </view>
  69. </view>
  70. </view>
  71. <view class="aiSuggest" v-if="aiSuggest">
  72. <text>AI 建议</text>
  73. <view>
  74. <text>{{aiSuggest}}</text>
  75. </view>
  76. </view>
  77. <view v-else class="aiSuggest button-all center" style="height: 50vw;" @click="getAiSuggest">获得ai建议</view>
  78. <uv-gap height="30"></uv-gap>
  79. <uv-divider text="我是有底线的"></uv-divider>
  80. <uv-gap height="30"></uv-gap>
  81. </view>
  82. <view v-if="!resInfo['code']">
  83. <p style="color: #f56c6c; font-size: 18px;">处理失败</p>
  84. </view>
  85. </view>
  86. </view>
  87. </template>
  88. <script>
  89. import img_api from '@/data/img_api';
  90. import send_message_ai from "@/data/medical_ai.js"
  91. import disease_suggest from '@/static/disease_suggest.js'
  92. export default {
  93. onLoad(options) {
  94. // 获取传递的对象参数,使用decodeURIComponent解码,并转为对象
  95. if ('timestamp' in options) {
  96. this.process_show = false;
  97. let timestamp = JSON.parse(decodeURIComponent(options.timestamp));
  98. this.timestamp = timestamp;
  99. console.log('timestamp: ',timestamp);
  100. let img_process_history = uni.getStorageSync('img_process_history');
  101. let img_process = img_process_history[timestamp];
  102. let resInfo = {code: 1, data: {disease: img_process['disease']}};
  103. for (let disease of img_process['disease']) {
  104. resInfo['data'][disease] = disease_suggest[disease];
  105. }
  106. this.resInfo = resInfo;
  107. this.timeString = img_process['time_string'];
  108. if(img_process['ai_suggest']) this.aiSuggest = img_process['ai_suggest'];
  109. }
  110. },
  111. data() {
  112. return {
  113. process_show: true,
  114. uploading: false,
  115. style:null,
  116. fileList1: [],
  117. resInfo: null,
  118. img_url: null,
  119. aiSuggest: null,
  120. timestamp: null,
  121. timeString: null,
  122. request: 1,
  123. processed: false
  124. }
  125. },
  126. methods: {
  127. getAiSuggest(){
  128. let disease = '';
  129. for (let value of this.resInfo['data']['disease']) disease += '、' + value;
  130. // 去掉第一个多余的 "、"
  131. disease = disease.substring(1);
  132. const content = '通过x胸腔图,已知患者有' + disease + "症状,请给出一些建议";
  133. console.log('content: ',content);
  134. if(this.request == 0){
  135. uni.showToast({duration:1000,icon:'none',title: '消息发送中,请稍等...'});
  136. setTimeout(() => uni.showLoading({title:'正在发送...'}), 1500);
  137. return ;
  138. }
  139. this.request = 0;
  140. uni.showLoading({title:'正在发送...'});
  141. send_message_ai(content).then(res => {
  142. console.log('send: res: ',res);
  143. this.aiSuggest = res;
  144. uni.hideLoading();
  145. this.request = 1;
  146. let img_process_history = uni.getStorageSync('img_process_history');
  147. img_process_history[this.timestamp]['ai_suggest'] = res;
  148. uni.setStorageSync('img_process_history', img_process_history);
  149. }).catch(err => {
  150. console.log('send: err: ',err);
  151. uni.hideLoading();
  152. uni.showToast({duration:1500,icon:'error',title: '获得失败'});
  153. this.request = 1;
  154. });
  155. },
  156. // 删除图片
  157. deletePic(event) {
  158. uni.showModal({
  159. title: '提示',
  160. content: '确定要删除这个照片吗?',
  161. cancelText: '再看看',
  162. confirmText: '删除',
  163. success: res => {
  164. if (res.confirm) {
  165. this[`fileList${event.name}`].splice(event.index, 1);
  166. this.processed = false;
  167. this.aiSuggest = null;
  168. this.resInfo = null;
  169. this.img_url = null;
  170. }
  171. }
  172. })
  173. },
  174. // 新增图片
  175. async afterRead(event) {
  176. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  177. let lists = [].concat(event.file)
  178. let fileListLen = this[`fileList${event.name}`].length
  179. lists.map((item) => {
  180. this[`fileList${event.name}`].push({
  181. ...item,
  182. status: 'uploading',
  183. message: '上传中'
  184. })
  185. });
  186. // 使用 Promise.all 来并行检查所有添加的文件
  187. await Promise.all(lists.map(async (item, index) => {
  188. let addedItem = this[`fileList${event.name}`][fileListLen + index];
  189. let isEnable = await this.$content_check.imgCheck(addedItem.thumb);
  190. console.log('isEnable: ',isEnable);
  191. if(isEnable === true) {
  192. addedItem.status = 'success';
  193. addedItem.message = '';
  194. }
  195. else{
  196. let indexToRemove = this[`fileList${event.name}`].findIndex(file => file === addedItem);
  197. if (indexToRemove !== -1) {
  198. this[`fileList${event.name}`].splice(indexToRemove, 1);
  199. }
  200. }
  201. }));
  202. },
  203. tip(){
  204. uni.showToast({
  205. icon:"error",
  206. title: '图片不能超过1MB',
  207. })
  208. },
  209. processImg() {
  210. if(!this.fileList1.length){
  211. uni.showToast({
  212. icon:"error",
  213. title: '请选择图片',
  214. })
  215. }
  216. if(!this.request || this.fileList1[0]['status'] != 'success'){
  217. uni.showToast({
  218. icon:"none",
  219. title: '图片处理中,请稍后...',
  220. });
  221. return ;
  222. }
  223. this.request = 0;
  224. uni.showLoading({title: '图片处理中...'});
  225. img_api(this.fileList1[0]['thumb']).then(res => {
  226. console.info('processImg: res: ',res);
  227. this.request = 1;
  228. this.processed = true;
  229. this.resInfo = res;
  230. this.img_url = 'data:image/png;base64,' + res['data']['image'];
  231. uni.hideLoading();
  232. uni.showToast({icon:'success',title: '处理成功',duration:1500});
  233. let img_process_history = uni.getStorageSync('img_process_history');
  234. const timestamp = Date.now();
  235. this.timestamp = timestamp;
  236. if(!img_process_history || Object.keys(img_process_history).length === 0) img_process_history = {};
  237. img_process_history[timestamp] = {disease: res['data']['disease'], time_string: this.$util.formatDateTime(timestamp)};
  238. uni.setStorageSync('img_process_history', img_process_history);
  239. }).catch(err => {
  240. this.request = 1;
  241. this.resInfo = err;
  242. console.error('processImg: err: ',err);
  243. uni.hideLoading();
  244. if(err === 'img_api: 没有token') uni.showToast({icon:'error',title: '未登陆',duration:1500});
  245. else uni.showToast({icon:'error',title: '处理失败',duration:1500});
  246. });
  247. }
  248. }
  249. }
  250. </script>
  251. <style lang="less">
  252. image{
  253. height: 100px;
  254. width: 100px;
  255. background-color: #fff;
  256. }
  257. .history{
  258. position: fixed;
  259. top: 10px;
  260. right: 20px;
  261. background-color: rgba(0, 0, 0, 0);
  262. font-size: 12px;
  263. color: #666;
  264. image{
  265. width: 35px;
  266. height: 35px;
  267. background-color: rgba(0, 0, 0, 0);
  268. }
  269. }
  270. .history:active{
  271. opacity: 0.6;
  272. }
  273. .content{
  274. padding:20px;
  275. }
  276. .arrow{
  277. height: 30px;
  278. width: 30px;
  279. margin: 20px;
  280. }
  281. .title{
  282. color: #777;
  283. font-size: 20px;
  284. font-weight: 600;
  285. }
  286. .diseaseItem{
  287. background-color: #f1f3f2;
  288. border-radius: 30px;
  289. padding: 20px;
  290. color: #333;
  291. letter-spacing: 1px;
  292. margin-bottom: 20px;
  293. > text{
  294. color: #000;
  295. font-size: 18px;
  296. font-weight: 600;
  297. }
  298. > view{
  299. border-radius: 20px;
  300. margin: 15px 0 5px;
  301. background-color: #ffffff;
  302. border-radius: 20px;
  303. padding: 15px;
  304. > text{
  305. font-size: 16px;
  306. color: #222;
  307. }
  308. view{
  309. padding: 1px 0;
  310. text{
  311. font-size: 15px;
  312. }
  313. }
  314. }
  315. }
  316. .aiSuggest{
  317. background-color: #f1f3f2;
  318. border: none;
  319. border-radius: 30px;
  320. padding: 20px;
  321. letter-spacing: 1px;
  322. margin-bottom: 20px;
  323. font-weight: 1000;
  324. color: #666;
  325. font-size: 28px;
  326. > text{
  327. color: #000;
  328. font-size: 18px;
  329. font-weight: 600;
  330. }
  331. > view{
  332. border-radius: 20px;
  333. margin: 10px 0;
  334. background-color: #ffffff;
  335. border-radius: 20px;
  336. padding: 15px;
  337. > text{
  338. font-size: 15px;
  339. }
  340. }
  341. }
  342. </style>