conductInspections.vue 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  1. <!-- 开展检查 -->
  2. <template>
  3. <view class="inspectAdd">
  4. <scroll-view scroll-y @scrolltolower="scrollGet" class="info-max-box">
  5. <view class="list">
  6. <view class="list-li srearch">
  7. <view class="srearch-l">{{newData.subName?newData.subName:'实验室名称'}}</view>
  8. </view>
  9. <view class="list-li" style="margin-bottom: 20rpx;border:none;">
  10. <view>
  11. {{newData.roomNum?newData.roomNum:''}}房间&{{newData.buildName?newData.buildName:'楼栋'}}&{{newData.deptName?newData.deptName:'学院单位'}}
  12. </view>
  13. </view>
  14. <view class="list-li">
  15. <view>现场照片</view>
  16. </view>
  17. <view v-if="form.photoList[0]" class="check-for-img-max-box">
  18. <view class="left-title-p"></view>
  19. <view class="right-img-box">
  20. <view class="img-box" v-for="(imgUrl,imgIndex) in form.photoList" :key="imgIndex">
  21. <img class="img-data" :src="baseUrl+imgUrl.fileUrl">
  22. <img class="position-img" :src="imagesUrl('commonality/icon_ssp_closure.png')"
  23. @click="delImg(imgIndex)">
  24. </view>
  25. <!-- <img class="add-button" :src="imagesUrl('safetyCheck/img_ssp_pz@1x.png')"
  26. @click="selectImage()" v-if="form.photoList.length<6"> -->
  27. </view>
  28. </view>
  29. <view class="list-li" @click="checkItemModuleButton('open')" style="border-bottom: none;">
  30. <view> {{newData.hazardCheckCode?newData.hazardCheckCode:''}}
  31. {{newData.hazardCheckName?newData.hazardCheckName:'检查项'}}
  32. </view>
  33. <view style="color: #0183FA;">
  34. <img :src="imagesUrl('commonality/icon_wd_gd@1x.png')">
  35. </view>
  36. </view>
  37. <view class="hazardCheckNum" @click="hiddenDangerClick()">
  38. <img class="hazardCheckNum-l" :src="imagesUrl('safetyCheck/icon_aqjc_yinhuan.png')">
  39. <view class="hazardCheckNum-r">{{'已连续出现'+hazardCheckNum+'次隐患'}} </view>
  40. </view>
  41. <view class="list-li" v-if="!form.checkFlag">
  42. <view>隐患描述</view>
  43. <view></view>
  44. </view>
  45. <view class="describe">
  46. <textarea v-if="!form.checkFlag && !checkItemModuleType" cursor-spacing="40" class="describe-n" type="text"
  47. v-model="form.hazardDescribe" maxlength="200" placeholder="请填写隐患描述"
  48. placeholder-style="font-size:24rpx;color:#999;"></textarea>
  49. </view>
  50. </view>
  51. <view class="voice">
  52. <view class="voice_t">
  53. <view class="voice_t_t" v-if="!form.voiceList[0]"><text>语音备注:</text><text>按住话筒录音</text></view>
  54. <view class="voice_t_b" v-if="form.voiceList[0]">语音备注:({{form.voiceList.length}})</view>
  55. </view>
  56. <view class="voice_b" v-if="form.voiceList[0]" v-for="(voiceItem,voiceIndex) in form.voiceList"
  57. :key="voiceIndex">
  58. <view class="voice_b_l" @tap="voicePlay(voiceItem.fileUrl)">
  59. <img class="add-button" :src="imagesUrl('safetyCheck/icon_yybz_yy.png')" />
  60. {{voiceItem.fileLength}}″
  61. </view>
  62. <img class="voice_b_r" :src="imagesUrl('safetyCheck/icon_yybz_sc.png')"
  63. @tap="voiceDele('',voiceIndex)" />
  64. </view>
  65. <!-- <view class="voice-btn">
  66. <img class="voice_t_r" :src="imagesUrl('commonality/icon_sskz_azsh.png')"
  67. @longpress.stop="recordButton(item,$event)" @touchmove.stop="cancelButton"
  68. @touchend.stop="sendButton(item,$event)" />
  69. <text>按住说话</text>
  70. </view> -->
  71. </view>
  72. </scroll-view>
  73. <checkItemModule :propsData="propsData" v-if="checkItemModuleType"></checkItemModule>
  74. <!-- <view class="sub-btn">
  75. <view @click="submitForm(1)">保存草稿</view>
  76. <view @click="submitForm(2)">提交</view>
  77. </view> -->
  78. <view class="sub-btn" v-if="!checkItemModuleType">
  79. <!-- #ifdef MP-WEIXIN -->
  80. <view
  81. class="broadcast_m no-long-press"
  82. @longpress.stop="recordButton(item,$event)"
  83. @touchmove.stop="cancelButton"
  84. @touchend.stop="sendButton(item,$event)"
  85. ></view>
  86. <!-- <img
  87. @longpress.stop="recordButton(item,$event)"
  88. @touchmove.stop="cancelButton"
  89. @touchend.stop="sendButton(item,$event)"
  90. :src="imagesUrl('safetyCheck/icon_aqjc_luyin.png')" /> -->
  91. <!-- #endif -->
  92. <!-- #ifdef WEB -->
  93. <view
  94. class="broadcast_m no-long-press"
  95. @touchstart="handleTouchStart"
  96. @touchmove="handleTouchMove"
  97. @touchend="handleTouchEnd"
  98. @touchcancel="handleTouchEnd"
  99. @contextmenu.prevent="handleContextMenu"
  100. ></view>
  101. <!-- <img
  102. @touchstart="handleTouchStart"
  103. @touchmove="handleTouchMove"
  104. @touchend="handleTouchEnd"
  105. @touchcancel="handleTouchEnd"
  106. @contextmenu.prevent="handleContextMenu"
  107. :src="imagesUrl('safetyCheck/icon_aqjc_luyin.png')" /> -->
  108. <!-- #endif -->
  109. <img @click="selectImage()" :src="imagesUrl('safetyCheck/icon_aqjc_paizhao.png')" />
  110. <img @click="submitForm(2)" :src="imagesUrl('safetyCheck/icon_aqjc_tijiao.png')" />
  111. </view>
  112. <view v-if="!checkItemModuleType" class="inspectRecord" @click="inspectRecordClick()">检查记录</view>
  113. </view>
  114. </template>
  115. <script>
  116. const myaudio = uni.createInnerAudioContext();
  117. // #ifdef WEB
  118. import Recorder from 'recorder-core';
  119. import 'recorder-core/src/engine/mp3';
  120. import 'recorder-core/src/engine/mp3-engine';
  121. // #endif
  122. import {
  123. config
  124. } from '@/api/request/config.js'
  125. import {
  126. securityAppCheckPlanCheckInfo,
  127. securityAppCheckSetOptionCheckCommit,
  128. securityAppCheckPhotoGetCheckNumBySub,
  129. } from '@/pages_safetyCheck/api/index.js'
  130. import checkItemModule from '@/pages_safetyCheck/component/checkItemModule.vue'
  131. export default {
  132. name: "inspectAdd",
  133. components: {
  134. checkItemModule
  135. },
  136. data() {
  137. return {
  138. baseUrl: config.base_url,
  139. form: {
  140. checkFlag: false,
  141. photoList: [],
  142. voiceList: [],
  143. },
  144. newData: {},
  145. radioList: [{
  146. id: 1,
  147. name: '符合',
  148. checked: false,
  149. },
  150. {
  151. id: 0,
  152. name: '不符合',
  153. checked: true,
  154. },
  155. ],
  156. pageType: '',
  157. sendLock: true, //发送锁,当为true时上锁,false时解锁发送
  158. recorderManager: wx.getRecorderManager(),
  159. optionData: null,
  160. //检查项组件数据
  161. checkItemModuleType: false,
  162. propsData: {},
  163. hazardCheckNum:0,
  164. //广播相关
  165. liveType: false,
  166. sendLock: true, //发送锁,当为true时上锁,false时解锁发送
  167. //H5
  168. recording: false,
  169. recorder: null,
  170. audioBlob: null,
  171. audioPath: null,
  172. }
  173. },
  174. onLoad(option) {
  175. let optionData = JSON.parse(decodeURIComponent(option.infoData));
  176. uni.setNavigationBarTitle({
  177. title: optionData.subName + '(' + (optionData.pageType == 0 ? (optionData.roomNum ? optionData
  178. .roomNum : '-') : (optionData
  179. .subRoom ? optionData
  180. .subRoom : '-')) + ')'
  181. })
  182. this.$set(this, 'pageType', optionData.pageType);
  183. this.$set(this, 'optionData', optionData);
  184. },
  185. onShow() {
  186. // #ifdef MP-WEIXIN
  187. if (this.recorderManager) {
  188. this.recorderManager.stop();
  189. }
  190. // #endif
  191. },
  192. mounted() {
  193. if (this.pageType == 0) {
  194. this.securityAppCheckPlanCheckInfo();
  195. this.securityAppCheckPhotoGetCheckNumBySub();
  196. }
  197. },
  198. methods: {
  199. //折叠展开
  200. inspectDot() {
  201. this.newData.inspectDot = !this.newData.inspectDot
  202. },
  203. //检查记录
  204. inspectRecordClick(){
  205. let infoData = this.optionData;
  206. infoData.curTabTow=1;//已检查
  207. uni.navigateTo({
  208. url: '/pages_safetyCheck/views/itemsManage/hiddenDangerItems?infoData=' +
  209. encodeURIComponent(JSON
  210. .stringify(infoData))
  211. });
  212. },
  213. //获取提交详情
  214. async securityAppCheckPlanCheckInfo() {
  215. let obj = {
  216. setOptionId: this.optionData.setOptionId,
  217. manageId: this.optionData.manageId,
  218. }
  219. const {
  220. data
  221. } = await securityAppCheckPlanCheckInfo(obj);
  222. if (data.code == 200) {
  223. data.data.inspectDot = true;
  224. this.$set(this, 'newData', data.data);
  225. //编辑的时候
  226. this.$set(this.form, 'checkFlag', data.data.checkFlag ? data.data.checkFlag : false);
  227. if(data.data.hazardDescribe){
  228. this.$set(this.form, 'hazardDescribe', data.data.hazardDescribe);
  229. }else{
  230. this.$set(this.newData,'hazardCheckPro',this.optionData.hazardCheckPro);
  231. this.$set(this.newData,'hazardCheckCode',this.optionData.hazardCheckCode);
  232. this.$set(this.newData,'hazardCheckName',this.optionData.hazardCheckName);
  233. this.$set(this.newData,'hazardCheckPro1',this.optionData.hazardCheckPro1);
  234. this.$set(this.newData,'hazardCheckCode1',this.optionData.hazardCheckCode1);
  235. this.$set(this.newData,'hazardCheckName1',this.optionData.hazardCheckName1);
  236. this.$set(this.newData,'hazardCheckPro2',this.optionData.hazardCheckPro2);
  237. this.$set(this.newData,'hazardCheckCode2',this.optionData.hazardCheckCode2);
  238. this.$set(this.newData,'hazardCheckName2',this.optionData.hazardCheckName2);
  239. this.$set(this.newData,'hazardCheckPoint',this.optionData.hazardCheckPoint);
  240. this.$set(this.form,'hazardDescribe',this.optionData.hazardCheckPoint);
  241. // let list=[];
  242. // list=data.data.hazardCheckPoint.split('#');
  243. // this.$set(this.form, 'hazardDescribe', list[0]);
  244. }
  245. this.$set(this.form, 'photoList', data.data.photoList ? data.data.photoList : []);
  246. this.$set(this.form, 'voiceList', data.data.voiceList ? data.data.voiceList : []);
  247. }
  248. },
  249. hiddenDangerClick(row) {
  250. if(!this.hiddenDangerRecordStatus){
  251. let infoData = this.optionData;
  252. infoData.subName=this.newData.subName;
  253. infoData.roomNum=this.newData.roomNum;
  254. infoData.hiddenDangerRecordStatus = true;//判断是否跳转隐患列表
  255. uni.navigateTo({
  256. url: '/pages_safetyCheck/views/inspectManage/hiddenDangerRecord?infoData=' +
  257. encodeURIComponent(JSON.stringify(infoData))
  258. });
  259. }
  260. },
  261. checkItemModuleButton(type, item,keyPoint) {
  262. if (type == 'open') {
  263. let obj = {
  264. infoType: this.pageType,
  265. checkType: 0,
  266. editStatus:this.optionData.editStatus,
  267. editItem:{
  268. hazardCheckName:this.newData.hazardCheckName,
  269. hazardCheckName1:this.newData.hazardCheckName1,
  270. hazardCheckName2:this.newData.hazardCheckName2,
  271. hazardCheckCode:this.newData.hazardCheckCode,
  272. hazardCheckCode1:this.newData.hazardCheckCode1,
  273. hazardCheckCode2:this.newData.hazardCheckCode2,
  274. hazardCheckPoint:this.newData.hazardCheckPoint,
  275. hazardCheckPro:this.newData.hazardCheckPro,
  276. hazardCheckPro1:this.newData.hazardCheckPro1,
  277. hazardCheckPro2:this.newData.hazardCheckPro2,
  278. setOptionId:this.newData.setOptionId,
  279. }
  280. }
  281. if (this.pageType == 0) {
  282. //检查
  283. obj.manageId = this.optionData.manageId
  284. obj.planSetId = this.optionData.planSetId
  285. }
  286. this.$set(this, 'propsData', obj);
  287. this.$set(this, 'checkItemModuleType', true);
  288. } else if (type == 'out') {
  289. this.$set(this, 'checkItemModuleType', false);
  290. this.$set(this, 'propsData', {});
  291. } else if (type == 'submit') {
  292. this.$set(this.newData, 'hazardCheckPro', item.hazardCheckPro);
  293. this.$set(this.newData, 'hazardCheckCode', item.hazardCheckCode);
  294. this.$set(this.newData, 'hazardCheckName', item.hazardCheckName);
  295. this.$set(this.newData, 'hazardCheckPro1', item.hazardCheckPro1);
  296. this.$set(this.newData, 'hazardCheckCode1', item.hazardCheckCode1);
  297. this.$set(this.newData, 'hazardCheckName1', item.hazardCheckName1);
  298. this.$set(this.newData, 'hazardCheckPro2', item.hazardCheckPro2);
  299. this.$set(this.newData, 'hazardCheckCode2', item.hazardCheckCode2);
  300. this.$set(this.newData, 'hazardCheckName2', item.hazardCheckName2);
  301. this.$set(this.newData, 'hazardCheckPoint', item.hazardCheckPoint);
  302. this.$set(this.form, 'hazardDescribe', keyPoint);
  303. // this.$set(this.optionData, 'setOptionId', item.setOptionId);
  304. this.$set(this.optionData, 'hazardCheckPro', item.hazardCheckPro);
  305. this.$set(this, 'checkItemModuleType', false);
  306. this.securityAppCheckPhotoGetCheckNumBySub();
  307. //编辑的时候
  308. if(this.optionData.editStatus){
  309. if(this.optionData.setOptionId!=this.newData.setOptionId){
  310. this.$set(this.form, 'photoList', []);
  311. this.$set(this.form, 'voiceList', []);
  312. }
  313. }
  314. }
  315. },
  316. //提交
  317. async submitForm(status) {
  318. if (!this.form.checkFlag) {
  319. if (!this.form.hazardDescribe) {
  320. uni.showToast({
  321. title: '请填写隐患描述!',
  322. icon: "none",
  323. mask: true,
  324. duration: 2000
  325. });
  326. return
  327. }
  328. if (!this.form.photoList[0]) {
  329. uni.showToast({
  330. title: '请选择现场照片!',
  331. icon: "none",
  332. mask: true,
  333. duration: 2000
  334. });
  335. return
  336. }
  337. }
  338. let obj = {
  339. checkFlag: this.form.checkFlag,
  340. checkStatus: 1,
  341. hazardDescribe: this.form.hazardDescribe,
  342. photoList: this.form.photoList,
  343. voiceList: this.form.voiceList,
  344. manageId: this.optionData.manageId,
  345. hazardCheckPro: this.newData.hazardCheckPro,
  346. hazardCheckCode: this.newData.hazardCheckCode,
  347. hazardCheckName: this.newData.hazardCheckName,
  348. hazardCheckPro2: this.newData.hazardCheckPro2,
  349. hazardCheckCode2: this.newData.hazardCheckCode2,
  350. hazardCheckName2: this.newData.hazardCheckName2,
  351. hazardCheckPro1: this.newData.hazardCheckPro1,
  352. hazardCheckCode1: this.newData.hazardCheckCode1,
  353. hazardCheckName1: this.newData.hazardCheckName1,
  354. hazardCheckPoint: this.form.hazardDescribe,
  355. }
  356. if(this.optionData.setOptionId){
  357. obj.setOptionId = this.optionData.setOptionId;
  358. }
  359. const {
  360. data
  361. } = await securityAppCheckSetOptionCheckCommit(obj);
  362. if (data.code == 200) {
  363. uni.$emit('infoPageSubmitButton', { type:1,subId:this.newData.subId });
  364. uni.showToast({
  365. title: '提交成功!',
  366. icon: "none",
  367. mask: true,
  368. duration: 2000
  369. });
  370. let infoData = this.optionData;
  371. infoData.setOptionId = data.data;
  372. uni.redirectTo({
  373. url: '/pages_safetyCheck/views/itemsManage/hiddenDangerItemsDetail?infoData=' +
  374. encodeURIComponent(JSON
  375. .stringify(infoData))
  376. });
  377. }
  378. },
  379. //获取检查项在当前实验室出现的次数
  380. async securityAppCheckPhotoGetCheckNumBySub() {
  381. let obj = {
  382. subId: this.optionData.subId,
  383. hazardCheckPro: this.optionData.hazardCheckPro,
  384. }
  385. const {
  386. data
  387. } = await securityAppCheckPhotoGetCheckNumBySub(obj);
  388. if (data.code == 200) {
  389. this.$set(this, 'hazardCheckNum', data.data);
  390. }
  391. },
  392. //滚动事件
  393. scrollGet() {},
  394. //单选按钮
  395. radioClick(d) {
  396. let self = this;
  397. d.checked = !d.checked
  398. if (d.checked) {
  399. //如果有选中的,循环把其他选中的取消
  400. this.radioList.forEach(function(item) {
  401. if (item.id == d.id) {
  402. self.$set(self.form, 'checkFlag', item.id);
  403. } else {
  404. item.checked = false;
  405. }
  406. })
  407. } else {
  408. }
  409. },
  410. /******图片上传******/
  411. selectImage() {
  412. let self = this;
  413. let photoMaxNun = 0;
  414. if (this.form.photoList.length > 5) {
  415. uni.showToast({
  416. title: '最多上传6张图片',
  417. icon: "none",
  418. mask: true,
  419. duration: 2000
  420. });
  421. return
  422. }
  423. photoMaxNun = 6 - this.form.photoList.length;
  424. uni.chooseImage({
  425. count: photoMaxNun,
  426. sizeType: ["original", "compressed"],
  427. sourceType: ["album", "camera"],
  428. success: function(res) {
  429. if (res.tempFilePaths[0]) {
  430. res.tempFilePaths.forEach(function(item, index) {
  431. self.uploadImg(item);
  432. })
  433. }
  434. }
  435. });
  436. },
  437. async uploadImg(tempFilePaths) {
  438. var self = this;
  439. uni.showLoading({
  440. title: '上传中',
  441. mask: true
  442. });
  443. uni.uploadFile({
  444. url: config.base_url + '/system/file/upload', //仅为示例,非真实的接口地址
  445. header: {
  446. 'Authorization': uni.getStorageSync('token')
  447. },
  448. filePath: tempFilePaths,
  449. name: 'file',
  450. formData: {
  451. 'user': 'test'
  452. },
  453. success: (uploadFileRes) => {
  454. let res = JSON.parse(uploadFileRes.data);
  455. if (res.code == 200) {
  456. this.form.photoList.push({
  457. 'fileUrl': res.data.url,
  458. 'fileName': res.data.name
  459. });
  460. } else {
  461. uni.showToast({
  462. title: res.msg,
  463. icon: "none",
  464. mask: true,
  465. duration: 2000
  466. });
  467. }
  468. },
  469. fail: err => {},
  470. complete: () => {
  471. uni.hideLoading()
  472. }
  473. });
  474. },
  475. //删除图片
  476. delImg(minIndex) {
  477. this.form.photoList.splice(minIndex, 1);
  478. this.$forceUpdate();
  479. },
  480. /******语音备注 *******/
  481. //语音备忘播放
  482. voicePlay(item) {
  483. myaudio.src = config.base_url + item;
  484. myaudio.play();
  485. },
  486. //语音备忘删除
  487. async voiceDele(item, voiceIndex) {
  488. let self = this;
  489. uni.showModal({
  490. title: '',
  491. cancelColor: '#999999',
  492. confirmColor: '#FF6E6E',
  493. content: '确定删除此语音吗?',
  494. success(res) {
  495. if (res.confirm) {
  496. console.log('用户点击确定')
  497. self.form.voiceList.splice(voiceIndex, 1);
  498. self.$forceUpdate();
  499. } else if (res.cancel) {
  500. console.log('用户点击取消')
  501. }
  502. }
  503. })
  504. },
  505. //录制
  506. recordButton(item, e) {
  507. console.log("按下")
  508. let self = this;
  509. if (this.form.voiceList.length >= 5) {
  510. uni.showToast({
  511. title: '语音备忘最多只能上传5条',
  512. icon: "none",
  513. mask: true,
  514. duration: 2000
  515. });
  516. return
  517. }
  518. this.liveType = true;
  519. console.log('录制', e)
  520. this.startPoint = e.touches[0]; //记录长按时开始点信息,后面用于计算上划取消时手指滑动的距离。
  521. const options = {
  522. duration: 60000,
  523. sampleRate: 16000,
  524. numberOfChannels: 1,
  525. encodeBitRate: 48000,
  526. format: 'mp3',
  527. frameSize: 50
  528. }
  529. this.recorderManager.start(options); //开始录音
  530. this.recorderManager.onStart(() => {
  531. console.log('recorder start')
  532. })
  533. this.recorderManager.onError((res) => {
  534. console.log(res);
  535. })
  536. uni.showToast({
  537. title: "正在录音,上划取消发送",
  538. icon: "none",
  539. duration: 60000 //先定义个60秒,后面可以手动调用wx.hideToast()隐藏
  540. });
  541. this.sendLock = false; //长按时是不上锁的。
  542. },
  543. //取消
  544. cancelButton(e) {
  545. console.log("移动")
  546. let self = this;
  547. this.liveType = false;
  548. console.log('取消', e)
  549. let moveLenght = e.touches[e.touches.length - 1].clientY - this.startPoint.clientY; //移动距离
  550. if (Math.abs(moveLenght) > 50) {
  551. uni.showToast({
  552. title: "松开手指,取消发送",
  553. icon: "none",
  554. duration: 60000
  555. });
  556. this.sendLock = true; //触发了上滑取消发送,上锁
  557. } else {
  558. uni.showToast({
  559. title: "正在录音,上划取消发送",
  560. icon: "none",
  561. duration: 60000
  562. });
  563. this.sendLock = false; //上划距离不足,依然可以发送,不上锁
  564. }
  565. },
  566. //发送
  567. sendButton(item, e) {
  568. console.log("松开")
  569. let self = this;
  570. this.liveType = false;
  571. console.log('发送', e)
  572. uni.hideToast(); //结束录音、隐藏Toast提示框
  573. this.recorderManager.stop(); //结束录音
  574. this.recorderManager.onStop((res) => {
  575. if (!this.sendLock) {
  576. this.uploadVoice(item, res.duration, res.tempFilePath);
  577. }
  578. console.log('停止录音', res.tempFilePath)
  579. console.log("sendLock", this.sendLock);
  580. })
  581. },
  582. //上传MP3
  583. async uploadVoice(item, times, tempFilePaths) {
  584. var self = this;
  585. uni.uploadFile({
  586. url: config.base_url + '/system/file/upload', //仅为示例,非真实的接口地址
  587. header: {
  588. 'Authorization': uni.getStorageSync('token')
  589. },
  590. filePath: tempFilePaths,
  591. name: 'file',
  592. formData: {
  593. 'user': 'test'
  594. },
  595. success: (uploadFileRes) => {
  596. let res = JSON.parse(uploadFileRes.data);
  597. if (res.code == 200) {
  598. console.log("上传成功", res)
  599. console.log(item)
  600. let seconds = Math.round((parseInt(times) % (1000 * 60)) / 1000);
  601. this.form.voiceList.push({
  602. 'fileLength': seconds,
  603. 'fileUrl': res.data.url,
  604. 'fileName': res.data.name
  605. })
  606. console.log(JSON.stringify(self.voice))
  607. //self.textParseUrlIps(res.data.url);
  608. // self.newData.imgList.push(res.data.url);
  609. } else {
  610. uni.showToast({
  611. title: res.msg,
  612. icon: "none",
  613. mask: true,
  614. duration: 2000
  615. });
  616. }
  617. },
  618. fail: err => {
  619. uni.hideLoading()
  620. },
  621. complete: () => {}
  622. });
  623. },// #ifdef WEB
  624. /* H5 */
  625. async initRecorder() {
  626. try {
  627. // 获取麦克风权限
  628. await navigator.mediaDevices.getUserMedia({ audio: true });
  629. this.recorder = new Recorder({
  630. type: "mp3", // 输出格式
  631. bitRate: 64, // 降低比特率提升兼容性
  632. // 不指定 sampleRate,让浏览器使用系统默认值(iOS 兼容性要求)
  633. });
  634. this.recorder.open(() => {
  635. // 初始化成功,继续 startRecord 流程
  636. this.startRecord();
  637. }, (error) => {
  638. console.error("录音器初始化失败:", error);
  639. uni.showToast({
  640. title: '麦克风权限获取失败,请允许麦克风权限',
  641. icon: "none",
  642. mask: true,
  643. duration: 2000
  644. });
  645. });
  646. } catch (err) {
  647. console.error("获取麦克风失败:", err);
  648. uni.showToast({
  649. title: '请允许麦克风权限',
  650. icon: "none",
  651. mask: true,
  652. duration: 2000
  653. });
  654. }
  655. },
  656. // 开始录音
  657. async startRecord() {
  658. let self = this;
  659. if (this.form.voiceList.length >= 5) {
  660. uni.showToast({
  661. title: '语音备忘最多只能上传5条',
  662. icon: "none",
  663. mask: true,
  664. duration: 2000
  665. });
  666. return
  667. }
  668. if (!this.recorder) {
  669. await this.initRecorder();
  670. // this.startRecord()
  671. return;
  672. }
  673. this.recorder.start();
  674. this.recording = true;
  675. this.liveType = true;
  676. // uni.showToast({ title: "录音开始", icon: "none" });
  677. uni.showToast({
  678. title: "正在录音,上划取消发送",
  679. icon: "none",
  680. duration: 60000 //先定义个60秒,后面可以手动调用wx.hideToast()隐藏
  681. });
  682. },
  683. // 停止录音
  684. stopRecord() {
  685. if (!this.recorder || !this.recording) return;
  686. this.recorder.stop((blob, duration) => {
  687. this.recording = false;
  688. this.liveType = false;
  689. this.audioBlob = blob;
  690. // 生成临时文件路径
  691. this.audioPath = URL.createObjectURL(blob);
  692. this.uploadAudio(duration);
  693. }, (error) => {
  694. console.error("录音失败:", error);
  695. uni.showToast({ title: "录音失败", icon: "none" });
  696. });
  697. },
  698. delRecord(){
  699. this.recorder.stop((blob, duration) => {
  700. this.recording = false;
  701. this.liveType = false;
  702. this.audioBlob = null;
  703. this.audioPath = null;
  704. })
  705. },
  706. // 上传录音文件
  707. uploadAudio(times) {
  708. let self = this;
  709. if (!this.audioBlob) return;
  710. // 1. 通过fetch获取Blob数据
  711. fetch(this.audioPath)
  712. .then(response => response.blob())
  713. .then(blob => {
  714. // 2. 将Blob转换为File对象
  715. const file = new File([blob], 'audio.mp3', { type: 'audio/mp3' });
  716. // console.log('file',file);
  717. // 3. 使用uni.uploadFile上传
  718. uni.uploadFile({
  719. url: config.base_url + '/system/file/upload',
  720. header: {
  721. 'Authorization': uni.getStorageSync('token')
  722. },
  723. file: file,
  724. name: 'file',
  725. formData: {
  726. 'user': 'test'
  727. },
  728. success: (uploadFileRes) => {
  729. let res = JSON.parse(uploadFileRes.data);
  730. if (res.code == 200) {
  731. console.log("上传成功", res)
  732. let seconds = Math.round((parseInt(times) % (1000 * 60)) / 1000);
  733. this.form.voiceList.push({
  734. 'fileLength': seconds,
  735. 'fileUrl': res.data.url,
  736. 'fileName': res.data.name
  737. })
  738. // console.log(JSON.stringify(self.voice))
  739. //self.textParseUrlIps(res.data.url);
  740. // self.newData.imgList.push(res.data.url);
  741. } else {
  742. uni.showToast({
  743. title: res.msg,
  744. icon: "none",
  745. mask: true,
  746. duration: 2000
  747. });
  748. }
  749. },
  750. fail: (err) => {
  751. console.error('上传失败', err);
  752. uni.showToast({
  753. title: res.msg,
  754. icon: "none",
  755. mask: true,
  756. duration: 2000
  757. });
  758. }
  759. });
  760. })
  761. .catch(error => {
  762. console.error('获取Blob数据失败', error);
  763. });
  764. },
  765. //H5 拖拽
  766. // 触摸开始
  767. handleTouchStart(event) {
  768. // 彻底阻止所有默认行为
  769. event.preventDefault();
  770. event.stopPropagation();
  771. this.touchStartY = event.touches[0].clientY;
  772. this.hasMoved = false;
  773. this.moveDirection = null;
  774. this.hasTriggeredMethod3 = false;
  775. // 设置长按定时器
  776. this.longPressTimer = setTimeout(() => {
  777. this.isLongPress = true;
  778. this.startRecord(); // 执行方法1
  779. }, 300); // 300ms触发长按
  780. },
  781. // 触摸移动
  782. handleTouchMove(event) {
  783. console.log("按下")
  784. let self = this;
  785. // 彻底阻止所有默认行为
  786. event.preventDefault();
  787. event.stopPropagation();
  788. if (!this.isLongPress) return;
  789. const currentY = event.touches[0].clientY;
  790. const deltaY = currentY - this.touchStartY;
  791. // 检测滑动方向(向上滑动为负值)
  792. if (Math.abs(deltaY) > 75) { // 增加阈值避免误触
  793. uni.showToast({
  794. title: "松开手指,取消发送",
  795. icon: "none",
  796. duration: 60000
  797. });
  798. this.hasMoved = true;
  799. this.moveDirection = deltaY < 0 ? 'up' : 'down';
  800. // 向上滑动执行方法3(确保只触发一次)
  801. if (this.moveDirection === 'up' && !this.hasTriggeredMethod3) {
  802. this.hasTriggeredMethod3 = true;
  803. this.delRecord();
  804. }
  805. }
  806. },
  807. // 触摸结束
  808. handleTouchEnd() {
  809. // 清除长按定时器
  810. clearTimeout(this.longPressTimer);
  811. uni.hideToast(); //结束录音、隐藏Toast提示框
  812. if (this.isLongPress) {
  813. this.stopRecord(); // 执行方法2
  814. }
  815. // 重置状态
  816. this.isLongPress = false;
  817. this.hasMoved = false;
  818. this.moveDirection = null;
  819. },
  820. // 关键:禁用上下文菜单(长按菜单)
  821. handleContextMenu(e) {
  822. e.preventDefault();
  823. return false;
  824. },
  825. // #endif
  826. }
  827. }
  828. </script>
  829. <style lang="stylus" scoped>
  830. @import '@/api/request/imagesUrl.styl';
  831. .inspectAdd {
  832. height: 100%;
  833. display flex;
  834. box-sizing: border-box;
  835. padding-bottom: 230rpx;
  836. box-sizing: border-box;
  837. .tip {
  838. width: 750rpx;
  839. height: 80rpx;
  840. background: rgba(1, 131, 250, 0.2);
  841. font-weight: normal;
  842. font-size: 28rpx;
  843. color: #0183FA;
  844. line-height: 80rpx;
  845. text-align: center;
  846. }
  847. .list {
  848. width: 750rpx;
  849. margin: 20rpx 0rpx 0;
  850. border-radius: 20rpx 20rpx 20rpx 20rpx;
  851. overflow: hidden;
  852. .list-li {
  853. display: flex;
  854. justify-content: space-between;
  855. align-items: center;
  856. padding: 0 30rpx;
  857. box-sizing: border-box;
  858. border-bottom: 1rpx solid #E0E0E0;
  859. background: #fff;
  860. >view:nth-of-type(1) {
  861. font-size: 30rpx;
  862. color: #333333;
  863. line-height: 100rpx;
  864. text-align: left;
  865. overflow: hidden;
  866. text-overflow: ellipsis;
  867. white-space: nowrap;
  868. }
  869. >view:nth-of-type(2) {
  870. font-size: 28rpx;
  871. color: #666666;
  872. line-height: 100rpx;
  873. text-align: left;
  874. display: flex;
  875. justify-content: space-between;
  876. align-items: center;
  877. >img {
  878. width: 30rpx;
  879. height: 30rpx;
  880. margin-left: 10rpx;
  881. }
  882. }
  883. }
  884. .hidden-content {
  885. width: 630rpx;
  886. min-height: 200rpx;
  887. background: #F5F5F5;
  888. border-radius: 20rpx 20rpx 20rpx 20rpx;
  889. margin: 20rpx 30rpx 0;
  890. padding: 20rpx;
  891. box-sizing: border-box;
  892. font-size: 28rpx;
  893. color: #666666;
  894. line-height: 39rpx;
  895. text-align: left;
  896. }
  897. .photo {
  898. display: flex;
  899. justify-content: flex-start;
  900. flex-wrap: wrap;
  901. margin-top: 20rpx;
  902. padding: 0 30rpx;
  903. box-sizing: border-box;
  904. >img {
  905. width: 150rpx;
  906. height: 150rpx;
  907. border-radius: 10rpx 10rpx 10rpx 10rpx;
  908. margin: 0 10rpx 10rpx 0;
  909. }
  910. >img:nth-of-type(4) {
  911. margin-right: 0;
  912. }
  913. }
  914. .describe {
  915. width: 750rpx;
  916. background: #fff;
  917. overflow: hidden;
  918. .describe-n {
  919. width: 690rpx;
  920. min-height: 180rpx;
  921. border-radius: 10rpx 10rpx 10rpx 10rpx;
  922. border: 1rpx solid #E0E0E0;
  923. margin: 40rpx;
  924. padding: 22rpx;
  925. box-sizing: border-box;
  926. background: #F5F5F5;
  927. }
  928. }
  929. .check-for-img-max-box {
  930. padding: 20px 28rpx;
  931. box-sizing: border-box;
  932. background: #fff;
  933. border-bottom: 2rpx solid #E0E0E0;
  934. .left-title-p {
  935. width: 100%;
  936. text-align: left;
  937. font-size: 30rpx;
  938. font-family: PingFang SC-Medium, PingFang SC;
  939. font-weight: 400;
  940. color: #333333;
  941. line-height: 80rpx;
  942. }
  943. .right-img-box {
  944. .img-box {
  945. display inline-block;
  946. height: 150rpx;
  947. width: 150rpx;
  948. position relative;
  949. margin: 0 10rpx 20rpx 0;
  950. border-radius 10rpx;
  951. overflow hidden;
  952. .img-data {
  953. height: 150rpx;
  954. width: 150rpx;
  955. }
  956. .position-img {
  957. position absolute;
  958. right: 0;
  959. top: 0;
  960. width: 36rpx;
  961. height: 36rpx;
  962. }
  963. }
  964. .img-box:nth-of-type(4n+4) {
  965. margin-right: 0rpx;
  966. }
  967. .add-button {
  968. margin: 0 0rpx 20rpx 0;
  969. border-radius 10rpx;
  970. overflow hidden;
  971. display inline-block;
  972. height: 150rpx;
  973. width: 150rpx;
  974. }
  975. }
  976. }
  977. .list-li:last-of-type {
  978. border: none;
  979. }
  980. .hazardCheckNum{
  981. border-bottom: 2rpx solid #E0E0E0;
  982. padding: 30rpx 40rpx 34rpx 40rpx;
  983. box-sizing: border-box;
  984. background: #fff;
  985. display: flex;
  986. justify-content: flex-end;
  987. align-items: center;
  988. .hazardCheckNum-l{
  989. width: 30rpx;
  990. height: 30rpx;
  991. margin-right: 18rpx;
  992. }
  993. .hazardCheckNum-r{
  994. font-size: 28rpx;
  995. color: #FF5900;
  996. line-height: 40rpx;
  997. text-align: left;
  998. }
  999. }
  1000. }
  1001. .srearch {
  1002. display: flex;
  1003. justify-content: space-between;
  1004. align-items: center;
  1005. .srearch-l {
  1006. font-size: 30rpx;
  1007. color: #333333;
  1008. line-height: 100rpx;
  1009. text-align: left;
  1010. }
  1011. .srearch-r {
  1012. width: 30rpx;
  1013. height: 30rpx;
  1014. margin-right: 0rpx;
  1015. }
  1016. }
  1017. /* 语音备注 */
  1018. .voice {
  1019. width: 750rpx;
  1020. min-height: 100rpx;
  1021. background: #FFFFFF;
  1022. border-radius: 20rpx 20rpx 20rpx 20rpx;
  1023. overflow: hidden;
  1024. .voice_t {
  1025. height: 100rpx;
  1026. display: flex;
  1027. justify-content: space-between;
  1028. align-items: center;
  1029. padding: 0 30rpx;
  1030. box-sizing: border-box;
  1031. border-top: 2rpx solid #E0E0E0;
  1032. .voice_t_t {
  1033. width: 100%;
  1034. display: flex;
  1035. justify-content: space-between;
  1036. >text:nth-of-type(1) {
  1037. font-size: 30rpx;
  1038. color: #333333;
  1039. line-height: 100rpx;
  1040. }
  1041. >text:nth-of-type(2) {
  1042. font-size: 28rpx;
  1043. color: #999999;
  1044. line-height: 100rpx;
  1045. }
  1046. }
  1047. .voice_t_b {
  1048. width: 100%;
  1049. font-size: 30rpx;
  1050. font-family: PingFang SC-Medium, PingFang SC;
  1051. font-weight: 400;
  1052. color: #333333;
  1053. line-height: 100rpx;
  1054. text-align: left;
  1055. }
  1056. }
  1057. .voice_b {
  1058. display flex;
  1059. justify-content flex-start;
  1060. align-items center;
  1061. margin-bottom: 20rpx;
  1062. padding: 0 30rpx;
  1063. box-sizing: border-box;
  1064. .voice_b_l {
  1065. width: 400rpx;
  1066. height: 40rpx;
  1067. background: #0183FA;
  1068. border-radius: 10rpx;
  1069. display flex;
  1070. justify-content flex-start;
  1071. align-items center;
  1072. font-size: 24rpx;
  1073. color: #FFFFFF;
  1074. line-height: 30rpx;
  1075. text-align: left;
  1076. >img {
  1077. width: 20rpx;
  1078. height: 20rpx;
  1079. margin-left: 16rpx;
  1080. margin-right: 20rpx;
  1081. }
  1082. }
  1083. .voice_b_r {
  1084. width: 28rpx;
  1085. height: 28rpx;
  1086. margin-left: 20rpx;
  1087. }
  1088. }
  1089. .voice-btn {
  1090. width: 150rpx;
  1091. height: 150rpx;
  1092. position: fixed;
  1093. right: 24rpx;
  1094. bottom: 176rpx;
  1095. >img {
  1096. width: 150rpx;
  1097. height: 150rpx;
  1098. position: absolute;
  1099. }
  1100. >text {
  1101. font-size: 24rpx;
  1102. color: #999999;
  1103. line-height: 30rpx;
  1104. text-align: center;
  1105. position: absolute;
  1106. top: 84rpx;
  1107. left: 26rpx;
  1108. }
  1109. }
  1110. }
  1111. }
  1112. .sub-btn {
  1113. display: flex;
  1114. justify-content: space-between;
  1115. position: fixed;
  1116. bottom: 30rpx;
  1117. width: 750rpx;
  1118. padding: 0 46rpx;
  1119. box-sizing: border-box;
  1120. >img {
  1121. width: 160rpx;
  1122. height: 160rpx;
  1123. }
  1124. .broadcast_m{
  1125. width: 160rpx;
  1126. height: 160rpx;
  1127. background-size:160rpx 160rpx !important;
  1128. background: url($imagesUrl+'safetyCheck/icon_aqjc_luyin.png');
  1129. }
  1130. }
  1131. .inspectRecord{
  1132. position: fixed;
  1133. top: 118rpx;
  1134. right: 0;
  1135. z-index: 200;
  1136. width: 160rpx;
  1137. height: 60rpx;
  1138. background: #0183FA;
  1139. border-radius: 50rpx 0rpx 0rpx 50rpx;
  1140. font-size: 30rpx;
  1141. color: #FFFFFF;
  1142. line-height: 60rpx;
  1143. text-align: center;
  1144. }
  1145. </style>