1
0

photos.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <template>
  2. <view class="app-page flex flex-col">
  3. <view class="e-fixed shadow-2 bg-white">
  4. <tm-search
  5. :clear="true"
  6. v-model="queryParams.keyword"
  7. :round="24"
  8. :shadow="0"
  9. confirmText="搜索"
  10. color="light-blue"
  11. insertColor="light-blue"
  12. align="center"
  13. @confirm="fnOnSearch()"
  14. ></tm-search>
  15. <tm-tabs v-if="team.list.length != 0" color="light-blue" :shadow="0" v-model="team.activeIndex" :list="team.list" align="center" @change="fnOnTabChange"></tm-tabs>
  16. </view>
  17. <!-- 占位区域 -->
  18. <view v-if="team.list.length != 0" style="width: 100vw;height: 184rpx;"></view>
  19. <view v-else style="width: 100vw;height: 94rpx;"></view>
  20. <view v-if="loading != 'success'" class="loading-wrap">
  21. <block v-if="loading == 'loading'">
  22. <tm-skeleton model="card"></tm-skeleton>
  23. <tm-skeleton model="card"></tm-skeleton>
  24. <tm-skeleton model="card"></tm-skeleton>
  25. <tm-skeleton model="card"></tm-skeleton>
  26. </block>
  27. <view v-else-if="loading == 'error'" class="loading-error flex flex-col flex-center">
  28. <tm-empty icon="icon-wind-cry" label="加载失败"><tm-button theme="light-blue" size="m" @click="fnGetData()">重新加载</tm-button></tm-empty>
  29. </view>
  30. </view>
  31. <view class="page-content pa-24 flex flex-col" v-else>
  32. <view v-if="dataList.length == 0" class="content-empty flex flex-center"><tm-empty icon="icon-shiliangzhinengduixiang-" label="暂无任何图片"></tm-empty></view>
  33. <block v-else>
  34. <block v-for="(item, index) in dataList" :key="index">
  35. <tm-translate animation-name="fadeUp" :wait="(index + 1) * 50">
  36. <view class="card mb-24 flex flex-col bg-white pa-24 round-3">
  37. <view class="thumbnail round-2" @click="fnPreview(item, index)">
  38. <image class="thumbnail-img round-2" :src="item.showThumbnail" mode="aspectFill"></image>
  39. </view>
  40. <view class="info">
  41. <view class=" mt-12 text-size-m text-grey-darken-1">图片名称:{{ item.name }}</view>
  42. <view class=" mt-12 text-size-m text-grey-darken-1">图片分组:{{ item.team || '未分组' }}</view>
  43. <view class=" mt-8 text-size-m text-grey-darken-1">拍摄日期:{{ { d: item.takeTime, f: 'yyyy年MM月dd日 星期w' } | formatTime }}</view>
  44. <view class=" mt-12 text-size-m text-grey-darken-1">拍摄地点:{{ item.location || '未填写拍摄地点' }}</view>
  45. </view>
  46. <view class="flex flex-center pt-24 desc-box text-size-m">
  47. <tm-button theme="light-blue" :shadow="0" block :width="300" :height="70" @click="fnEdit(item)">编辑</tm-button>
  48. <tm-button class="ml-36" theme="red" :shadow="0" block :width="300" :height="70" @click="fnDelete(item, index)">删除</tm-button>
  49. </view>
  50. </view>
  51. </tm-translate>
  52. </block>
  53. <tm-flotbutton @click="fnToTopPage" :offset="[16, 80]" color="bg-gradient-light-blue-accent" size="m" icon="icon-angle-up"></tm-flotbutton>
  54. <view class="load-text ">{{ loadMoreText }}</view>
  55. </block>
  56. <tm-flotbutton :show-text="true" color="bg-gradient-orange-accent" @click="fnAdd()"></tm-flotbutton>
  57. </view>
  58. <!-- 编辑或新增 -->
  59. <tm-poup v-model="poupShow" position="bottom" height="85vh" @change="fnOnPoupChange">
  60. <view class="poup-content">
  61. <view class="poup-head text-align-center text-weight-b text-size-g ma-24">{{ form.id != undefined ? '编辑图片' : '新增图片' }}</view>
  62. <scroll-view :enable-flex="true" class="poup-body pa-24 pt-0 pb-0" :scroll-y="true" :scroll-top="poupBodyScrollTop" @touchmove.stop @scroll="fnOnPoupBodyScroll">
  63. <tm-input
  64. :adjust-position="true"
  65. :round="3"
  66. clear
  67. :borderBottom="false"
  68. title="图片名称"
  69. bg-color="grey-lighten-5"
  70. v-model="form.name"
  71. placeholder="请输入图片名称"
  72. ></tm-input>
  73. <tm-input
  74. name="team"
  75. :adjust-position="true"
  76. :round="3"
  77. bg-color="grey-lighten-5"
  78. :borderBottom="false"
  79. title="图片分组"
  80. placeholder="请选择输入或分组"
  81. v-model="form.team"
  82. >
  83. <tm-pickers slot="rightBtn" rang-key="name" :default-value.sync="team.selected" :list="team.selectList" @confirm="fnOnSelectTeamConfirm">
  84. <tm-button size="m" :dense="true" :shadow="0" theme="bg-gradient-light-blue-accent">选择</tm-button>
  85. </tm-pickers>
  86. </tm-input>
  87. <view class="pl-32 mb-24 input-tips text-grey text-size-s">填写提示:图片分组可选择,也可以输入新的分组名称</view>
  88. <tm-pickersDate
  89. :full-number="true"
  90. :show-detail="{ year: true, month: true, day: true, hour: true, min: true, sec: true }"
  91. :default-value="takeTime"
  92. @confirm="fnOnTakeTimeConfirm"
  93. >
  94. <tm-input
  95. title="拍摄时间"
  96. :adjust-position="true"
  97. :round="3"
  98. bg-color="grey-lighten-5"
  99. :borderBottom="false"
  100. placeholder="请选择拍摄时间"
  101. disabled
  102. :value="takeTime"
  103. ></tm-input>
  104. </tm-pickersDate>
  105. <tm-input
  106. :borderBottom="false"
  107. :adjust-position="true"
  108. :round="3"
  109. clear
  110. title="拍摄地点"
  111. bg-color="grey-lighten-5"
  112. v-model="form.location"
  113. placeholder="请输入拍摄地点"
  114. ></tm-input>
  115. <tm-input
  116. :borderBottom="false"
  117. :vertical="false"
  118. clear
  119. :adjust-position="true"
  120. inputType="textarea"
  121. :round="3"
  122. title="图片描述"
  123. :height="160"
  124. bg-color="grey-lighten-5"
  125. v-model="form.description"
  126. placeholder="请输入图片描述"
  127. ></tm-input>
  128. <tm-input
  129. name="url"
  130. clear
  131. :borderBottom="false"
  132. :adjust-position="true"
  133. :round="3"
  134. title="图片地址"
  135. bg-color="grey-lighten-5"
  136. v-model="form.url"
  137. placeholder="请输入或选择图片"
  138. @clear="fnOnUrlInputChange"
  139. @blur="fnOnUrlInputChange"
  140. @input="fnOnUrlInputChange"
  141. >
  142. <tm-button slot="rightBtn" size="m" :dense="true" :shadow="0" theme="bg-gradient-light-blue-accent" @click="fnShowAttachmentsSelect('url')">选择</tm-button>
  143. </tm-input>
  144. <tm-input
  145. name="thumbnail"
  146. :borderBottom="false"
  147. :adjust-position="true"
  148. :round="3"
  149. clear
  150. title="缩略图片"
  151. bg-color="grey-lighten-5"
  152. v-model="form.thumbnail"
  153. placeholder="请输入或选择缩略图"
  154. >
  155. <tm-button slot="rightBtn" size="m" :dense="true" :shadow="0" theme="bg-gradient-light-blue-accent" @click="fnShowAttachmentsSelect('thumbnail')">
  156. 选择
  157. </tm-button>
  158. </tm-input>
  159. <view class="ma-30 mt-12 pb-12">
  160. <view class="mb-12"><text class="text-size-m">图片预览</text></view>
  161. <image :src="form.showThumbnail" mode="aspectFit"></image>
  162. </view>
  163. </scroll-view>
  164. <view class="btn-wrap flex flex-center bg-white">
  165. <tm-button :width="300" :height="72" theme="bg-gradient-blue-accent" @click="fnSave()">保存</tm-button>
  166. <tm-button :width="300" :height="72" theme="bg-gradient-blue-grey-accent" @click="poupShow = false">关 闭</tm-button>
  167. </view>
  168. </view>
  169. </tm-poup>
  170. <!-- 附件选择文件 -->
  171. <attachment-select selectType="image" v-if="attachmentsSelectShow" @on-select="fnOnAttachmentsSelect" @on-close="fnOnAttachmentsSelectClose"></attachment-select>
  172. </view>
  173. </template>
  174. <script>
  175. import throttle from '@/utils/throttle.js';
  176. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  177. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  178. import tmSearch from '@/tm-vuetify/components/tm-search/tm-search.vue';
  179. import tmTabs from '@/tm-vuetify/components/tm-tabs/tm-tabs.vue';
  180. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  181. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  182. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  183. import tmPoup from '@/tm-vuetify/components/tm-poup/tm-poup.vue';
  184. import tmInput from '@/tm-vuetify/components/tm-input/tm-input.vue';
  185. import tmPickersDate from '@/tm-vuetify/components/tm-pickersDate/tm-pickersDate.vue';
  186. import tmPickers from '@/tm-vuetify/components/tm-pickers/tm-pickers.vue';
  187. import AttachmentSelect from '@/components/attachment-select/attachment-select.vue';
  188. export default {
  189. components: {
  190. tmSkeleton,
  191. tmButton,
  192. tmSearch,
  193. tmTabs,
  194. tmEmpty,
  195. tmFlotbutton,
  196. tmTranslate,
  197. tmPoup,
  198. tmInput,
  199. tmPickersDate,
  200. tmPickers,
  201. AttachmentSelect
  202. },
  203. data() {
  204. return {
  205. loading: 'loading',
  206. team: {
  207. activeIndex: 0,
  208. list: [],
  209. selected: [],
  210. selectList: []
  211. },
  212. queryParams: {
  213. size: 10,
  214. page: 0,
  215. sort: 'createTime,desc',
  216. sort: 'id,asc'
  217. },
  218. result: null,
  219. dataList: [],
  220. total: 0,
  221. isLoadMore: false,
  222. loadMoreText: '加载中...',
  223. poupShow: false,
  224. attachmentsSelectShow: false,
  225. selectAttachmentsType: 'url',
  226. takeTime: undefined,
  227. form: {
  228. id: undefined,
  229. location: undefined,
  230. name: undefined,
  231. takeTime: undefined,
  232. team: undefined,
  233. thumbnail: undefined,
  234. url: undefined,
  235. description: undefined
  236. },
  237. poupBodyScrollTop: 0
  238. };
  239. },
  240. onLoad() {
  241. this.fnSetPageTitle('图库管理');
  242. this.fnGetTeamList();
  243. },
  244. created() {
  245. this.fnGetData();
  246. },
  247. onPullDownRefresh() {
  248. this.queryParams.page = 0;
  249. this.dataList = [];
  250. this.fnGetData();
  251. },
  252. onReachBottom(e) {
  253. if (this.result.hasNext) {
  254. this.queryParams.page += 1;
  255. this.isLoadMore = true;
  256. this.fnGetData();
  257. } else {
  258. uni.showToast({
  259. icon: 'none',
  260. title: '没有更多数据了'
  261. });
  262. }
  263. },
  264. methods: {
  265. // 获取分类列表
  266. fnGetTeamList() {
  267. this.$httpApi.admin
  268. .getPhotosTeams()
  269. .then(res => {
  270. if (res.status == 200) {
  271. let _list = res.data;
  272. this.team.selectList = _list.map((item, index) => {
  273. return {
  274. id: index,
  275. name: item,
  276. value: item
  277. };
  278. });
  279. if (_list.length > 1) {
  280. _list.unshift('全部');
  281. this.team.list = _list;
  282. }
  283. }
  284. })
  285. .catch(err => {});
  286. },
  287. fnOnSearch() {
  288. this.queryParams.page = 0;
  289. this.isLoadMore = false;
  290. this.fnToTopPage();
  291. this.fnGetData();
  292. },
  293. fnOnTabChange(index) {
  294. this.queryParams.team = index == 0 ? undefined : this.team.list[index];
  295. this.queryParams.page = 0;
  296. this.dataList = [];
  297. this.fnToTopPage();
  298. this.fnGetData();
  299. },
  300. fnOnTakeTimeConfirm(e) {
  301. this.takeTime = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.min}:${e.sec}`;
  302. this.form.takeTime = new Date(this.takeTime).getTime();
  303. },
  304. fnOnSelectTeamConfirm(e) {
  305. const _select = e[0].data;
  306. this.form.team = _select.value;
  307. },
  308. fnGetData() {
  309. uni.showLoading({
  310. mask: true,
  311. title: '加载中...'
  312. });
  313. // 设置状态为加载中
  314. if (!this.isLoadMore) {
  315. this.loading = 'loading';
  316. }
  317. this.loadMoreText = '加载中...';
  318. this.$httpApi.admin
  319. .getPhotos(this.queryParams)
  320. .then(res => {
  321. if (res.status == 200) {
  322. this.loadMoreText = res.data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  323. this.result = res.data;
  324. this.total = res.data.total;
  325. let _list = res.data.content.map(item => {
  326. // 处理显示的图片
  327. item['showThumbnail'] = this.$utils.checkThumbnailUrl(item.thumbnail);
  328. return item;
  329. });
  330. if (this.isLoadMore) {
  331. this.dataList = this.dataList.concat(_list);
  332. } else {
  333. this.dataList = _list;
  334. }
  335. this.loading = 'success';
  336. } else {
  337. uni.$tm.toast('加载失败,请重试!');
  338. this.loading = 'error';
  339. }
  340. })
  341. .catch(err => {
  342. console.error(err);
  343. uni.$tm.toast('加载失败,请重试!');
  344. this.loading = 'error';
  345. this.loadMoreText = '加载失败,请下拉刷新!';
  346. })
  347. .finally(() => {
  348. setTimeout(() => {
  349. uni.hideLoading();
  350. uni.stopPullDownRefresh();
  351. }, 300);
  352. });
  353. },
  354. fnOnAttachmentsSelectClose() {
  355. this.attachmentsSelectShow = false;
  356. },
  357. fnOnPoupBodyScroll(e) {
  358. throttle(() => {
  359. this.poupBodyScrollTop = e.detail.scrollTop;
  360. }, 1000);
  361. },
  362. fnOnPoupChange(e) {
  363. if (!e) {
  364. this.fnResetForm();
  365. }
  366. },
  367. fnOnUrlInputChange() {
  368. if (this.form.url) {
  369. this.$set(this.form, 'showThumbnail', this.$utils.checkThumbnailUrl(this.form.url));
  370. }
  371. },
  372. fnShowAttachmentsSelect(type) {
  373. this.selectAttachmentsType = type;
  374. this.attachmentsSelectShow = true;
  375. },
  376. // 监听附件选择
  377. fnOnAttachmentsSelect(file) {
  378. if (this.selectAttachmentsType == 'url') {
  379. this.form.url = file.path;
  380. this.form.showThumbnail = this.$utils.checkThumbnailUrl(file.path);
  381. if (!this.form.thumbnail) {
  382. this.form.thumbnail = file.path;
  383. }
  384. } else {
  385. this.form.thumbnail = file.path;
  386. }
  387. this.attachmentsSelectShow = false;
  388. },
  389. fnResetForm() {
  390. this.form = { id: undefined, location: undefined, name: undefined, takeTime: undefined, team: undefined, thumbnail: undefined, url: undefined, description: undefined };
  391. this.takeTime = uni.$tm.dayjs(new Date().getTime()).format('YYYY-MM-DD HH:mm:ss');
  392. },
  393. fnEdit(item) {
  394. this.poupBodyScrollTop = 0;
  395. if (!item.takeTime) {
  396. item.takeTime = new Date().getTime();
  397. }
  398. this.takeTime = uni.$tm.dayjs(item.takeTime).format('YYYY-MM-DD HH:mm:ss');
  399. this.form = item;
  400. if (this.form.team) {
  401. this.team.selected = [this.team.selectList.findIndex(x => x.name == this.form.team)];
  402. } else {
  403. this.team.selected = [];
  404. }
  405. this.poupShow = true;
  406. },
  407. // 新增
  408. fnAdd() {
  409. this.fnResetForm();
  410. this.poupBodyScrollTop = 0;
  411. this.poupShow = true;
  412. },
  413. // 保存
  414. fnSave() {
  415. if (!this.form.name) {
  416. return uni.$tm.toast('请填写图片名称!');
  417. }
  418. if (!this.$utils.checkIsUrl(this.form.url)) {
  419. return uni.$tm.toast('请选择或输入正确的图片地址!');
  420. }
  421. if (!this.$utils.checkIsUrl(this.form.thumbnail)) {
  422. return uni.$tm.toast('请选择或输入正确的缩略图地址!');
  423. }
  424. if (this.form.id == undefined) {
  425. this.$httpApi.admin
  426. .createPhotos(this.form)
  427. .then(res => {
  428. if (res.status == 200) {
  429. uni.$tm.toast(`保存成功!`);
  430. this.poupShow = false;
  431. setTimeout(() => {
  432. this.fnResetForm();
  433. this.fnGetTeamList();
  434. uni.startPullDownRefresh();
  435. }, 1000);
  436. } else {
  437. uni.$tm.toast('操作失败,请重试!');
  438. }
  439. })
  440. .catch(err => {
  441. uni.$tm.toast('操作失败,请重试!');
  442. });
  443. } else {
  444. this.$httpApi.admin
  445. .updatePhotosById(this.form.id, this.form)
  446. .then(res => {
  447. if (res.status == 200) {
  448. uni.$tm.toast(`保存成功!`);
  449. let updateIndex = this.dataList.findIndex(x => x.id == this.form.id);
  450. this.$set(this.dataList, updateIndex, this.form);
  451. setTimeout(() => {
  452. this.fnGetTeamList();
  453. }, 500);
  454. } else {
  455. uni.$tm.toast('操作失败,请重试!');
  456. }
  457. })
  458. .catch(err => {
  459. uni.$tm.toast('操作失败,请重试!');
  460. });
  461. }
  462. },
  463. // 删除
  464. fnDelete(item, index) {
  465. uni.$eShowModal({
  466. title: '提示',
  467. content: `您是否删除名为 ${item.name} 的图片?`,
  468. showCancel: true,
  469. cancelText: '否',
  470. cancelColor: '#999999',
  471. confirmText: '是',
  472. confirmColor: '#03a9f4'
  473. })
  474. .then(res => {
  475. this.$httpApi.admin
  476. .deletePhotosById(item.id)
  477. .then(res => {
  478. if (res.status == 200) {
  479. uni.$tm.toast(`${item.name} 分类已删除!`);
  480. this.dataList.splice(index, 1);
  481. } else {
  482. uni.$tm.toast('操作失败,请重试!');
  483. }
  484. })
  485. .catch(err => {
  486. uni.$tm.toast('操作失败,请重试!');
  487. });
  488. })
  489. .catch(err => {});
  490. },
  491. // 预览
  492. fnPreview(item, index) {
  493. uni.previewImage({
  494. current: index,
  495. urls: this.dataList.map(x => x.url),
  496. indicator: 'number',
  497. loop: true
  498. });
  499. }
  500. }
  501. };
  502. </script>
  503. <style lang="scss" scoped>
  504. .app-page {
  505. width: 100vw;
  506. min-height: 100vh;
  507. }
  508. .loading-wrap {
  509. padding: 24rpx;
  510. .loading-error {
  511. height: 65vh;
  512. }
  513. }
  514. .btn-wrap {
  515. box-sizing: border-box;
  516. padding-top: 12rpx;
  517. padding-bottom: 12rpx;
  518. box-shadow: 0rpx -4rpx 24rpx rgba(0, 0, 0, 0.05);
  519. }
  520. .card {
  521. box-shadow: 0rpx 4rpx 24rpx rgba(0, 0, 0, 0.05);
  522. }
  523. .thumbnail {
  524. width: 100%;
  525. &-img {
  526. width: 100%;
  527. height: 300rpx;
  528. }
  529. }
  530. .poup-content {
  531. overflow: hidden;
  532. }
  533. .poup-body {
  534. height: 69vh;
  535. box-sizing: border-box;
  536. touch-action: none;
  537. }
  538. </style>