App.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. // 全局数据管理
  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. // 从全局变量中获取当前路由(避开uni API)
  59. const currentRoute = uni.$appGlobal?.globalData?.value?.currentRoute || ''
  60. if (currentRoute === 'pages/nurseRecordPage/nurseRecordPage' ||
  61. currentRoute === 'pages/addVisitatPage/addVisitatPage' ||
  62. currentRoute === 'pages/prescriptionExecute/prescriptionExecute') {
  63. uni.$emit('callGetPDAScanInfo', code);
  64. } else {
  65. if (code.length === 10) {
  66. Util.getPatInfoNew(code, (patInfo) => {
  67. uni.navigateTo({
  68. url: '../patMainPage/patMainPage'
  69. })
  70. })
  71. }
  72. }
  73. } catch (err) {
  74. console.error('条码接收回调异常:', err.message, err.stack)
  75. }
  76. }
  77. })
  78. }
  79. // 设置广播模式
  80. function setBROADCAST() {
  81. const main2 = plus.android.runtimeMainActivity() // 获取activity
  82. const Intent = plus.android.importClass('android.content.Intent')
  83. const intent2 = new Intent('com.android.scanner.service_settings')
  84. intent2.putExtra('barcode_send_mode', 'BROADCAST')
  85. main2.sendBroadcast(intent2)
  86. setBROADCASTACTION()
  87. }
  88. // 设置广播动作
  89. function setBROADCASTACTION() {
  90. const main2 = plus.android.runtimeMainActivity() // 获取activity
  91. const Intent = plus.android.importClass('android.content.Intent')
  92. const intent2 = new Intent('com.android.scanner.service_settings')
  93. intent2.putExtra('action_barcode_broadcast', 'com.seuic.scan')
  94. main2.sendBroadcast(intent2)
  95. }
  96. // 开始扫描
  97. function startScan() {
  98. main.registerReceiver(receiver, filter)
  99. }
  100. // 停止扫描
  101. function stopScan() {
  102. main.unregisterReceiver(receiver)
  103. }
  104. // 挂载到全局,方便其他地方访问
  105. uni.$appGlobal = {
  106. globalData: globalData
  107. }
  108. </script>
  109. <style>
  110. /**app.wxss**/
  111. .container {
  112. height: 100%;
  113. display: flex;
  114. flex-direction: column;
  115. align-items: center;
  116. justify-content: space-between;
  117. box-sizing: border-box;
  118. background: #fff;
  119. font-family: Arial, Helvetica, sans-serif;
  120. }
  121. page {
  122. height: 100%;
  123. width: 100%;
  124. box-sizing: border-box;
  125. background: #fff;
  126. color: #333;
  127. font-size: 28rpx;
  128. overflow: hidden;
  129. }
  130. .multiBtn-content {
  131. height: 90rpx;
  132. font-size: 30rpx;
  133. color: #fff;
  134. padding: none;
  135. position: fixed;
  136. bottom: 0;
  137. left: 0;
  138. right: 0;
  139. display: flex;
  140. }
  141. .multiBtn-left {
  142. flex: 1;
  143. align-items: center;
  144. justify-content: center;
  145. display: flex;
  146. border-radius: 0 !important;
  147. color: #000;
  148. }
  149. .multiBtn-right {
  150. flex: 1;
  151. align-items: center;
  152. justify-content: center;
  153. display: flex;
  154. background-color: #1890ff;
  155. color: #ffffff;
  156. border-radius: 0 !important;
  157. font-size: 34rpx;
  158. }
  159. /* 首页组件样式 */
  160. .patlist .van-icon__image,
  161. .patlist .van-icon--image {
  162. margin-top: 10rpx;
  163. width: 78rpx;
  164. height: 78rpx;
  165. }
  166. .searchcontent .van-search{
  167. background: none !important;
  168. padding-left: 0 !important;
  169. padding-right: 0 !important;
  170. }
  171. /* 表单详情页组件样式 */
  172. .comboboxclass .van-checkbox {
  173. margin-top: 12rpx !important;
  174. }
  175. .radioboxclass .van-radio{
  176. margin-top: 12rpx !important;
  177. }
  178. .inputclass .van-cell {
  179. padding: 0 !important;
  180. }
  181. .inputclass .uni-input-input{
  182. font-size: 28rpx;
  183. }
  184. .inputclass .uni-input-placeholder{
  185. font-size: 28rpx;
  186. }
  187. .inputclass .van-field__input{
  188. height: 60rpx;
  189. }
  190. .selectclass .van-cell {
  191. min-height: 60rpx !important;
  192. line-height: 60rpx !important;
  193. padding: 0rpx !important;
  194. }
  195. .selectclass .van-cell__value {
  196. text-align: left;
  197. line-height: normal;
  198. overflow: hidden;
  199. text-overflow: ellipsis;
  200. white-space: nowrap;
  201. padding-top: 10rpx;
  202. }
  203. </style>