logList.uvue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view class="container">
  3. <!-- 列表内容 -->
  4. <!-- #ifdef APP -->
  5. <list-view class="list" :bounces="false" :scroll-y="true" :custom-nested-scroll="true"
  6. @scrolltolower="loadData(null)" associative-container="nested-scroll-view">
  7. <list-item class="list-item" type="10">
  8. <!-- #endif -->
  9. <view class="download-card" v-for="(item, index) in logs" :key="index" >
  10. <view @click="enterItem(item.id)">
  11. <view class="info-row">
  12. <text class="label">数据表:</text>
  13. <text class="value">{{ item.module }}</text>
  14. </view>
  15. <view class="info-row">
  16. <text class="label">数据类型:</text>
  17. <text class="value">{{ item.dataid == 0 ? "新增" : "变更" }}</text>
  18. </view>
  19. <view class="info-row">
  20. <text class="label">日志内容:</text>
  21. <text class="value">{{ item.content }}</text>
  22. </view>
  23. <view class="info-row">
  24. <text class="label">操作结果:</text>
  25. <text class="value">{{ item.status === 1 ? "操作成功" : "操作失败" }}</text>
  26. </view>
  27. <view class="info-row">
  28. <text class="label">操作时间:</text>
  29. <text class="value">{{ item.dataid === 0 ? item.createtime : item.updatetime }}</text>
  30. </view>
  31. </view>
  32. </view>
  33. <!-- #ifdef APP -->
  34. </list-item type="20">
  35. <list-item class="loading">
  36. <uni-loading :loading="loading" color="#999" :text="loadingText"></uni-loading>
  37. </list-item>
  38. </list-view>
  39. <!-- #endif -->
  40. </view>
  41. </template>
  42. <script setup>
  43. import { ref, reactive } from 'vue'
  44. import { getList, selectPageSql } from '@/api/work';
  45. import { downloadDataFromAPI, uploadDataToAPI } from '@/utils/dataProcessor';
  46. const backPressOptions = reactive({
  47. from: 'backbutton'
  48. } as OnBackPressOptions)
  49. onBackPress((options : OnBackPressOptions) : boolean | null => {
  50. console.log('onBackPress', options)
  51. // 使用reLaunch代替switchTab,避免多层跳转时的闪回问题
  52. // reLaunch会关闭所有页面并打开到目标页面,适合需要完全重置导航栈的场景
  53. uni.reLaunch({
  54. url: `/pages/work/index`,
  55. })
  56. // 返回true表示拦截默认返回行为
  57. return true
  58. })
  59. type Log = {
  60. id : number,
  61. module : string,
  62. dataid : number,
  63. content : string,
  64. status : number,
  65. params : string,
  66. updatetime : string,
  67. createtime: string
  68. }
  69. var initLog = [] as Log[]
  70. var logs = ref<Log[]>([]);
  71. const loading = ref(false)
  72. const isEnded = ref(false)
  73. const loadingError = ref('')
  74. const currentPage = ref(1)
  75. const map = ref(new Map<number, string>([[1, '未执行'], [2, '执行中'], [3, '执行完'], [4, '有错误']]))
  76. const loadingText = computed((): string => {
  77. if (loading.value) {
  78. return "加载中..."
  79. } else if (isEnded.value) {
  80. return "没有更多了"
  81. } else if (loadingError.value.length > 0) {
  82. return loadingError.value
  83. } else {
  84. return ""
  85. }
  86. })
  87. // #ifdef APP-ANDROID
  88. const loadData = (loadComplete : (() => void) | null) {
  89. if (loading.value || isEnded.value) {
  90. return
  91. }
  92. loading.value = true
  93. let offset = currentPage.value === 1 ? 0 : (currentPage.value-1) * 10
  94. selectPageSql('app_log', 'createtime', offset).then((res : UTSJSONObject) => {
  95. console.log(res)
  96. let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
  97. if (dataList != null && dataList.length > 0) {
  98. dataList.forEach(item => {
  99. if (item != null) {
  100. let log = JSON.parse<Log>(item.toJSONString());
  101. if (log != null) {
  102. initLog.push(log)
  103. }
  104. }
  105. });
  106. currentPage.value++
  107. }else{
  108. isEnded.value = true
  109. }
  110. logs.value = initLog
  111. loading.value = false
  112. if (loadComplete != null) {
  113. loadComplete()
  114. }
  115. })
  116. }
  117. onMounted(() => {
  118. loadData(null)
  119. })
  120. // #endif
  121. // #ifdef H5
  122. logs = [{
  123. id: 1,
  124. module: "app_media_info",
  125. dataid: 0,
  126. content : "新增数据成功",
  127. params: "1CFA1040-00#S",
  128. createtime: "2025-06-23",
  129. updatetime: "2025-06-23",
  130. status: 1
  131. }, {
  132. id: 2,
  133. module: "app_media_info",
  134. dataid: 0,
  135. content : "新增数据成功",
  136. params: "1CFA1040-00#S",
  137. createtime: "2025-06-23",
  138. updatetime: "2025-06-23",
  139. status: 1
  140. }] as Log[];
  141. // #endif
  142. const enterItem = (id : number) => {
  143. uni.navigateTo({
  144. url: `/pages/work/log/logDetail?id=${id}`
  145. });
  146. }
  147. defineExpose({
  148. loadData,
  149. backPressOptions
  150. })
  151. </script>
  152. <style scope>
  153. .container {
  154. padding: 24rpx;
  155. background-color: #f0f4f8;
  156. flex: 1;
  157. display: flex;
  158. flex-direction: column;
  159. font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
  160. /* #ifndef APP-ANDROID */
  161. min-height: 100vh;
  162. /* #endif */
  163. height: 120rpx;
  164. }
  165. .search-bar {
  166. background-color: #ffffff;
  167. border-radius: 10rpx;
  168. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  169. }
  170. /* 搜索输入框:占满容器剩余空间,放在按钮左侧 */
  171. .search-input {
  172. /* 清除默认输入框样式 */
  173. border: none;
  174. background: transparent;
  175. width: 70%;
  176. margin-left: 10rpx;
  177. }
  178. /* 扫描按钮:放在输入框右侧,距离最右10rpx */
  179. .scan-btn {
  180. justify-content: center;
  181. align-items: center; /* 新增:按钮内部图标垂直居中 */
  182. /* 关键:右侧10rpx边距,实现"距离最右10rpx" */
  183. margin-left: auto; /* 自动推到flex容器最右侧 */
  184. margin-right: 10rpx; /* 与容器右边缘保持10rpx间距 */
  185. }
  186. .download-card {
  187. background: #ffffff;
  188. border-radius: 20rpx;
  189. padding: 24rpx 32rpx;
  190. box-shadow: 0 8rpx 15rpx rgba(0, 43, 92, 0.1);
  191. display: flex;
  192. flex-direction: column;
  193. margin-bottom: 20rpx;
  194. margin-top: 40rpx;
  195. margin-left: 20rpx;
  196. margin-right: 20rpx;
  197. }
  198. .download-card .view {
  199. margin-bottom: 16rpx;
  200. }
  201. /* 信息行 */
  202. .info-row {
  203. display: flex;
  204. flex-direction: row;
  205. /* #ifdef H5 */
  206. font-size: 28rpx;
  207. color: #33475b;
  208. /* #endif */
  209. align-items: center;
  210. }
  211. .info-row>.label {
  212. margin-left: 10rpx;
  213. }
  214. .info-row>.value {
  215. margin-left: 10rpx;
  216. }
  217. .btn-panel {
  218. display: flex;
  219. justify-content: space-between;
  220. align-items: center;
  221. margin-left: 5rpx;
  222. margin-right: 5rpx;
  223. }
  224. .label {
  225. font-weight: bold;
  226. color: #102a43;
  227. min-width: 100rpx;
  228. }
  229. .value {
  230. flex: 1;
  231. white-space: nowrap;
  232. overflow: hidden;
  233. text-overflow: ellipsis;
  234. }
  235. .btn {
  236. align-self: flex-end;
  237. background-color: #00aaff;
  238. color: #fff;
  239. border: none;
  240. border-radius: 32rpx;
  241. padding: 2rpx 30rpx;
  242. font-size: 24rpx;
  243. font-weight: bold;
  244. /* #ifndef APP-ANDROID */
  245. transition: background-color 0.3s ease;
  246. /* #endif */
  247. margin-top: 30rpx;
  248. }
  249. .process-value {
  250. width: 120rpx;
  251. min-width: 100rpx;
  252. text-align: center;
  253. border-radius: 10rpx;
  254. }
  255. .bg-green {
  256. background-color: seagreen;
  257. }
  258. .bg-yellow {
  259. background-color: yellow;
  260. }
  261. .bg-black {
  262. background-color: #102a43;
  263. }
  264. .btn-first {
  265. margin-left: 5rpx;
  266. }
  267. .btn-second {
  268. margin-right: 5rpx;
  269. margin-left: auto;
  270. }
  271. .loading {
  272. padding: 30px;
  273. align-items: center;
  274. }
  275. .list {
  276. flex: 1;
  277. background-color: #ffffff;
  278. }
  279. .list-item {
  280. flex-direction: column;
  281. margin-top: 10px;
  282. padding: 10px;
  283. }
  284. </style>