PersonList.uvue 7.4 KB

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