App.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <script setup>
  2. import { onLaunch, onShow } from '@dcloudio/uni-app'
  3. import { getCurrentInstance, onMounted, ref ,onUnmounted} from 'vue' // 从vue导入
  4. import Util from './utils/util.js'
  5. // 全局数据管理(替代 globalData)
  6. const globalData = ref({
  7. share: false,
  8. height: 0,
  9. statusBarHeight: uni.getSystemInfoSync()['statusBarHeight'],
  10. overlayVisible: false,
  11. quickMenu: {
  12. x: 0,
  13. y: 0
  14. },
  15. currentRoute: '' // 存储当前页面路由
  16. })
  17. // 获取全局实例
  18. const app = getCurrentInstance()
  19. app.appContext.config.globalProperties.$globalData = globalData
  20. // 变量声明
  21. let main, receiver, filter
  22. // 生命周期:应用启动
  23. onLaunch(() => {
  24. uni.getSystemInfo({
  25. success: (res) => {
  26. globalData.height = res.statusBarHeight
  27. }
  28. })
  29. setBROADCAST()
  30. })
  31. // 生命周期:页面显示
  32. onShow(() => {})
  33. // 生命周期:创建
  34. onMounted(() => {
  35. initScan()
  36. startScan()
  37. })
  38. // 生命周期:卸载
  39. onUnmounted(() => {
  40. // 页面退出时卸载监听,防止重复扫码
  41. stopScan()
  42. })
  43. // 初始化扫描
  44. function initScan() {
  45. main = plus.android.runtimeMainActivity() // 获取activity
  46. const IntentFilter = plus.android.importClass('android.content.IntentFilter')
  47. filter = new IntentFilter()
  48. filter.addAction('com.seuic.scan') // 广播动作
  49. receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
  50. onReceive: function(context, intent) {
  51. try {
  52. plus.android.importClass(intent)
  53. let code = intent.getStringExtra('scannerdata')
  54. // 清除空白字符(确保code格式正确)
  55. if (typeof code === 'string') {
  56. code = code.replace(/\s+/g, '')
  57. }
  58. console.log('接收的条码数据:', code)
  59. // 从全局变量中获取当前路由(避开uni API)
  60. const currentRoute = uni.$appGlobal?.globalData?.value?.currentRoute || ''
  61. // 目标页面路由
  62. const targetPagePath = 'pages/nurseRecordPage/nurseRecordPage'
  63. if (currentRoute === targetPagePath) {
  64. // 调用目标页面方法(需确保页面已加载)
  65. // 延迟确保页面已完全加载
  66. setTimeout(() => {
  67. const pages = getCurrentPages()
  68. if (!pages || pages.length === 0) {
  69. console.error('页面栈为空,无法获取页面实例')
  70. return
  71. }
  72. const currentPage = pages[pages.length - 1]
  73. // 严格检查页面实例和函数是否存在
  74. if (!currentPage) {
  75. console.error('当前页面实例不存在')
  76. return
  77. }
  78. if (!currentPage.$vm) {
  79. console.error('当前页面的Vue实例不存在')
  80. return
  81. }
  82. if (typeof currentPage.$vm.getPDAScanInfo !== 'function') {
  83. console.error('目标页面未定义getPDAScanInfo函数,请检查页面代码')
  84. return
  85. }
  86. // 所有检查通过后调用
  87. currentPage.$vm.getPDAScanInfo(code)
  88. }, 100) // 适当延长延迟时间,确保页面初始化完成
  89. } else {
  90. if (code.length === 10) {
  91. Util.getPatInfoNew(code, (patInfo) => {
  92. uni.navigateTo({
  93. url: '../patMainPage/patMainPage'
  94. })
  95. })
  96. }
  97. }
  98. } catch (err) {
  99. console.error('条码接收回调异常:', err.message, err.stack)
  100. }
  101. }
  102. })
  103. }
  104. // 设置广播模式
  105. function setBROADCAST() {
  106. const main2 = plus.android.runtimeMainActivity() // 获取activity
  107. const Intent = plus.android.importClass('android.content.Intent')
  108. const intent2 = new Intent('com.android.scanner.service_settings')
  109. intent2.putExtra('barcode_send_mode', 'BROADCAST')
  110. main2.sendBroadcast(intent2)
  111. setBROADCASTACTION()
  112. }
  113. // 设置广播动作
  114. function setBROADCASTACTION() {
  115. const main2 = plus.android.runtimeMainActivity() // 获取activity
  116. const Intent = plus.android.importClass('android.content.Intent')
  117. const intent2 = new Intent('com.android.scanner.service_settings')
  118. intent2.putExtra('action_barcode_broadcast', 'com.seuic.scan')
  119. main2.sendBroadcast(intent2)
  120. }
  121. // 开始扫描
  122. function startScan() {
  123. main.registerReceiver(receiver, filter)
  124. }
  125. // 停止扫描
  126. function stopScan() {
  127. main.unregisterReceiver(receiver)
  128. }
  129. // 挂载到全局,方便其他地方访问
  130. uni.$appGlobal = {
  131. globalData: globalData
  132. }
  133. </script>
  134. <style>
  135. /**app.wxss**/
  136. .container {
  137. height: 100%;
  138. display: flex;
  139. flex-direction: column;
  140. align-items: center;
  141. justify-content: space-between;
  142. box-sizing: border-box;
  143. background: #fff;
  144. font-family: Arial, Helvetica, sans-serif;
  145. }
  146. page {
  147. height: 100%;
  148. width: 100%;
  149. box-sizing: border-box;
  150. background: #fff;
  151. color: #333;
  152. font-size: 28rpx;
  153. overflow: hidden;
  154. }
  155. .multiBtn-content {
  156. height: 90rpx;
  157. font-size: 30rpx;
  158. color: #fff;
  159. padding: none;
  160. position: fixed;
  161. bottom: 0;
  162. left: 0;
  163. right: 0;
  164. display: flex;
  165. }
  166. .multiBtn-left {
  167. flex: 1;
  168. align-items: center;
  169. justify-content: center;
  170. display: flex;
  171. border-radius: 0 !important;
  172. }
  173. .multiBtn-right {
  174. flex: 1;
  175. align-items: center;
  176. justify-content: center;
  177. display: flex;
  178. background-color: #1890ff;
  179. color: #ffffff;
  180. border-radius: 0 !important;
  181. font-size: 34rpx;
  182. }
  183. /* 首页组件样式 */
  184. .patlist .van-icon__image,
  185. .patlist .van-icon--image {
  186. margin-top: 10rpx;
  187. width: 78rpx;
  188. height: 78rpx;
  189. }
  190. .searchcontent .van-search{
  191. background: none !important;
  192. padding-left: 0 !important;
  193. padding-right: 0 !important;
  194. }
  195. /* 表单详情页组件样式 */
  196. .comboboxclass .van-checkbox {
  197. margin-top: 12rpx !important;
  198. }
  199. .radioboxclass .van-radio{
  200. margin-top: 12rpx !important;
  201. }
  202. .inputclass .van-cell {
  203. padding: 0 !important;
  204. }
  205. .inputclass .uni-input-input{
  206. font-size: 28rpx;
  207. }
  208. .inputclass .uni-input-placeholder{
  209. font-size: 28rpx;
  210. }
  211. .inputclass .van-field__input{
  212. height: 60rpx;
  213. }
  214. .selectclass .van-cell {
  215. min-height: 60rpx !important;
  216. line-height: 60rpx !important;
  217. padding: 0rpx !important;
  218. }
  219. .selectclass .van-cell__value {
  220. text-align: left;
  221. line-height: normal;
  222. overflow: hidden;
  223. text-overflow: ellipsis;
  224. white-space: nowrap;
  225. padding-top: 10rpx;
  226. }
  227. </style>