img_process.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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=2097152
  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" 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. request: 1,
  120. aiSuggest: null,
  121. timestamp: null,
  122. timeString: null
  123. }
  124. },
  125. methods: {
  126. getAiSuggest(){
  127. let disease = '';
  128. for (let value of this.resInfo['data']['disease']) disease += '、' + value;
  129. // 去掉第一个多余的 "、"
  130. disease = disease.substring(1);
  131. const content = '通过x胸腔图,已知患者有' + disease + "症状,请给出一些建议";
  132. console.log('content: ',content);
  133. if(this.request == 0){
  134. uni.showToast({duration:1000,icon:'none',title: '消息发送中,请稍等...'});
  135. setTimeout(() => uni.showLoading({title:'正在发送...'}), 1500);
  136. return ;
  137. }
  138. this.request = 0;
  139. uni.showLoading({title:'正在发送...'});
  140. send_message_ai(content).then(res => {
  141. console.log('send: res: ',res);
  142. this.aiSuggest = res;
  143. uni.hideLoading();
  144. this.request = 1;
  145. let img_process_history = uni.getStorageSync('img_process_history');
  146. img_process_history[this.timestamp]['ai_suggest'] = res;
  147. uni.setStorageSync('img_process_history', img_process_history);
  148. }).catch(err => {
  149. console.log('send: err: ',err);
  150. uni.hideLoading();
  151. uni.showToast({duration:1500,icon:'error',title: '获得失败'});
  152. this.request = 1;
  153. });
  154. },
  155. // 删除图片
  156. deletePic(event) {
  157. uni.showModal({
  158. title: '提示',
  159. content: '确定要删除这个照片吗?',
  160. cancelText: '再看看',
  161. confirmText: '删除',
  162. success: res => {
  163. if (res.confirm) {
  164. this[`fileList${event.name}`].splice(event.index, 1)
  165. }
  166. }
  167. })
  168. },
  169. // 新增图片
  170. async afterRead(event) {
  171. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  172. let lists = [].concat(event.file)
  173. let fileListLen = this[`fileList${event.name}`].length
  174. lists.map((item) => {
  175. this[`fileList${event.name}`].push({
  176. ...item,
  177. status: 'uploading',
  178. message: '上传中'
  179. })
  180. })
  181. for (let i = 0; i < lists.length; i++) {
  182. const result = '';
  183. let item = this[`fileList${event.name}`][fileListLen]
  184. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  185. status: 'success',
  186. message: '',
  187. url: result
  188. }))
  189. fileListLen++;
  190. }
  191. },
  192. tip(){
  193. uni.showToast({
  194. icon:"error",
  195. title: '图片不能超过2M',
  196. })
  197. },
  198. processImg() {
  199. if(!this.request){
  200. uni.showToast({
  201. icon:"none",
  202. title: '图片处理中,请稍后...',
  203. });
  204. }
  205. else if(!this.fileList1.length){
  206. uni.showToast({
  207. icon:"error",
  208. title: '请选择图片',
  209. })
  210. }
  211. else{
  212. this.request = 0;
  213. uni.showLoading({title: '图片处理中...'});
  214. img_api(this.fileList1[0]['thumb']).then(res => {
  215. console.info('processImg: res: ',res);
  216. this.request = 1;
  217. this.resInfo = res;
  218. this.img_url = 'data:image/png;base64,' + res['data']['image'];
  219. uni.hideLoading();
  220. uni.showToast({icon:'success',title: '处理成功',duration:1500});
  221. let img_process_history = uni.getStorageSync('img_process_history');
  222. const timestamp = Date.now();
  223. this.timestamp = timestamp;
  224. if(!img_process_history || Object.keys(img_process_history).length === 0) img_process_history = {};
  225. img_process_history[timestamp] = {disease: res['data']['disease'], time_string: this.$util.formatDateTime(timestamp)};
  226. uni.setStorageSync('img_process_history', img_process_history);
  227. }).catch(err => {
  228. this.request = 1;
  229. this.resInfo = err;
  230. console.error('processImg: err: ',err);
  231. uni.hideLoading();
  232. if(err === 'img_api: 没有token') uni.showToast({icon:'error',title: '未登陆',duration:1500});
  233. else uni.showToast({icon:'error',title: '处理失败',duration:1500});
  234. });
  235. }
  236. }
  237. }
  238. }
  239. </script>
  240. <style lang="less">
  241. image{
  242. height: 100px;
  243. width: 100px;
  244. background-color: #fff;
  245. }
  246. .history{
  247. position: fixed;
  248. top: 10px;
  249. right: 20px;
  250. background-color: rgba(0, 0, 0, 0);
  251. font-size: 12px;
  252. color: #666;
  253. image{
  254. width: 35px;
  255. height: 35px;
  256. background-color: rgba(0, 0, 0, 0);
  257. }
  258. }
  259. .history:active{
  260. opacity: 0.6;
  261. }
  262. .content{
  263. padding:20px;
  264. }
  265. .arrow{
  266. height: 30px;
  267. width: 30px;
  268. margin: 20px;
  269. }
  270. .title{
  271. color: #777;
  272. font-size: 20px;
  273. font-weight: 600;
  274. }
  275. .diseaseItem{
  276. background-color: #f1f3f2;
  277. border-radius: 30px;
  278. padding: 20px;
  279. color: #333;
  280. letter-spacing: 1px;
  281. margin-bottom: 20px;
  282. > text{
  283. color: #000;
  284. font-size: 18px;
  285. font-weight: 600;
  286. }
  287. > view{
  288. border-radius: 20px;
  289. margin: 15px 0 5px;
  290. background-color: #ffffff;
  291. border-radius: 20px;
  292. padding: 15px;
  293. > text{
  294. font-size: 16px;
  295. color: #222;
  296. }
  297. view{
  298. padding: 1px 0;
  299. text{
  300. font-size: 15px;
  301. }
  302. }
  303. }
  304. }
  305. .aiSuggest{
  306. background-color: #f1f3f2;
  307. border: none;
  308. border-radius: 30px;
  309. padding: 20px;
  310. letter-spacing: 1px;
  311. margin-bottom: 20px;
  312. font-weight: 1000;
  313. color: #666;
  314. font-size: 28px;
  315. > text{
  316. color: #000;
  317. font-size: 18px;
  318. font-weight: 600;
  319. }
  320. > view{
  321. border-radius: 20px;
  322. margin: 10px 0;
  323. background-color: #ffffff;
  324. border-radius: 20px;
  325. padding: 15px;
  326. > text{
  327. font-size: 15px;
  328. }
  329. }
  330. }
  331. </style>