index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view class="page_container">
  3. <custom-nav-bar :title="`发布${!!momentsType ? '视频' : '图文'}`">
  4. <view class="nav_right_action" slot="more">
  5. <u-button
  6. type="primary"
  7. :disabled="fileList.length === 0 && !content"
  8. size="mini"
  9. loadingSize="12"
  10. :loading="publishing"
  11. text="发布"
  12. @click="publish"
  13. >
  14. </u-button>
  15. </view>
  16. </custom-nav-bar>
  17. <view class="edit_area">
  18. <u-textarea
  19. v-model="content"
  20. count
  21. border="none"
  22. maxlength="150"
  23. height="120"
  24. placeholder="请输入"
  25. >
  26. </u-textarea>
  27. <view class="media_row">
  28. <u-upload
  29. :fileList="fileList"
  30. :accept="!!momentsType ? 'video' : 'image'"
  31. :capture="!!momentsType ? ['album'] : ['album', 'camera']"
  32. @afterRead="afterRead"
  33. @delete="deletePic"
  34. multiple
  35. :maxCount="9"
  36. ></u-upload>
  37. </view>
  38. </view>
  39. <view class="settings_row">
  40. <setting-item
  41. :icon="visible_icon"
  42. show-right
  43. :title="permission === 3 ? '不给谁看' : '谁可以看'"
  44. @click="chooseVisible"
  45. >
  46. <view class="choose_row" slot="right">{{ choosedNameStr }}</view>
  47. </setting-item>
  48. <setting-item
  49. :icon="notify_icon"
  50. show-right
  51. title="提醒谁看"
  52. @click="chooseRemind"
  53. >
  54. <view class="choose_row" slot="right">{{ getRemindStr }}</view>
  55. </setting-item>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import CustomNavBar from "../../../components/CustomNavBar/index.vue";
  61. import SettingItem from "./SettingItem.vue";
  62. import { ContactChooseTypes, CustomType, PageEvents } from "../../../constant";
  63. import { getPurePath, toastWithCallback } from "../../../util/common";
  64. import { publishMoments } from "../../../api/moments";
  65. import IMSDK from "openim-uniapp-polyfill";
  66. import { base64ToPath } from "image-tools";
  67. const visible_icon = "https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/moments_visible.png";
  68. const notify_icon = "https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/moments_notify.png";
  69. export default {
  70. components: {
  71. CustomNavBar,
  72. SettingItem,
  73. },
  74. data() {
  75. return {
  76. content: "",
  77. fileList: [],
  78. choosedUserInfoList: [],
  79. choosedGroupInfoList: [],
  80. remindUserInfoList: [],
  81. permission: 0,
  82. visible_icon,
  83. notify_icon,
  84. choosedNameStr: "公开",
  85. momentsType: 0,
  86. publishing: false,
  87. };
  88. },
  89. computed: {
  90. getRemindStr() {
  91. let str = "";
  92. this.remindUserInfoList.map((user) => (str += `${user.nickname}、`));
  93. return str.slice(0, str.length - 1);
  94. },
  95. },
  96. onLoad(options) {
  97. this.momentsType = JSON.parse(options.momentsType || "0");
  98. },
  99. methods: {
  100. publish() {
  101. this.publishing = true;
  102. const workMoment = {
  103. content: {
  104. type: this.momentsType,
  105. metas: this.fileList.map((file) => ({
  106. thumb: file.thumb,
  107. original: file.original || file.thumb,
  108. })),
  109. text: this.content,
  110. },
  111. permission: this.permission,
  112. atUserIDs: this.remindUserInfoList.map((user) => user.userID),
  113. permissionGroupIDs: this.choosedGroupInfoList.map(
  114. (group) => group.groupID,
  115. ),
  116. permissionUserIDs: this.choosedUserInfoList.map((user) => user.userID),
  117. };
  118. console.log(workMoment);
  119. publishMoments(workMoment)
  120. .then(() =>
  121. toastWithCallback("发布成功!", () => {
  122. uni.$emit(PageEvents.RefreshMoments);
  123. uni.navigateBack();
  124. }),
  125. )
  126. .catch((err) => {
  127. console.log(err);
  128. uni.$u.toast("发布失败!");
  129. })
  130. .finally(() => (this.publishing = false));
  131. },
  132. async uploadFile(path) {
  133. const nameIdx = path.lastIndexOf("/") + 1;
  134. const typeIdx = path.lastIndexOf(".") + 1;
  135. const fileName = path.slice(nameIdx);
  136. const fileType = path.slice(typeIdx);
  137. try {
  138. const {
  139. data: { url },
  140. } = await IMSDK.asyncApi(IMSDK.IMMethods.UploadFile, IMSDK.uuid(), {
  141. filepath: getPurePath(path),
  142. name: fileName,
  143. contentType: fileType,
  144. uuid: IMSDK.uuid(),
  145. });
  146. return url;
  147. } catch (error) {
  148. console.log(error);
  149. return "";
  150. }
  151. },
  152. afterRead(event) {
  153. console.log(event);
  154. let lists = [].concat(event.file);
  155. lists.map(async (item) => {
  156. const idx =
  157. this.fileList.push({
  158. ...item,
  159. status: "uploading",
  160. message: "上传中",
  161. }) - 1;
  162. const purePath = getPurePath(item.url);
  163. if (!!this.momentsType) {
  164. const { path } = await IMSDK.getVideoCover(purePath);
  165. const thumb = await this.uploadFile(getPurePath(path));
  166. const original = await this.uploadFile(purePath);
  167. this.fileList.splice(idx, 1, {
  168. ...this.fileList[idx],
  169. status: thumb && original ? "success" : "failed",
  170. message: "",
  171. thumb,
  172. original,
  173. });
  174. } else {
  175. const thumb = await this.uploadFile(purePath);
  176. this.fileList.splice(idx, 1, {
  177. ...this.fileList[idx],
  178. status: thumb ? "success" : "failed",
  179. message: "",
  180. thumb,
  181. });
  182. }
  183. });
  184. },
  185. deletePic(event) {
  186. this.fileList.splice(event.index, 1);
  187. },
  188. getWhoCanSee({
  189. choosedUserInfoList,
  190. choosedGroupInfoList,
  191. permission,
  192. choosedNameStr,
  193. }) {
  194. this.choosedUserInfoList = choosedUserInfoList;
  195. this.choosedGroupInfoList = choosedGroupInfoList;
  196. this.permission = permission;
  197. this.choosedNameStr = choosedNameStr;
  198. if (permission === 1) {
  199. this.remindUserInfoList = [];
  200. }
  201. },
  202. getCheckedUsers(data) {
  203. this.remindUserInfoList = [...data];
  204. },
  205. chooseVisible() {
  206. uni.$u.route("/pages_im/pages/moments/mementsVisibility/index", {
  207. choosedUserInfoList: JSON.stringify(this.choosedUserInfoList),
  208. choosedGroupInfoList: JSON.stringify(this.choosedGroupInfoList),
  209. permission: this.permission,
  210. choosedNameStr: this.choosedNameStr,
  211. });
  212. },
  213. chooseRemind() {
  214. if (this.permission === 1) {
  215. uni.$u.toast("可见范围为私密时,此功能不可用!");
  216. return;
  217. }
  218. uni.$u.route("/pages_im/pages/common/contactChoose/index", {
  219. type: ContactChooseTypes.GetList,
  220. checkedUserInfoList: JSON.stringify(this.remindUserInfoList),
  221. });
  222. },
  223. },
  224. };
  225. </script>
  226. <style lang="scss" scoped>
  227. .page_container {
  228. background-color: #f8f8f8;
  229. .nav_right_action {
  230. margin-right: 44rpx;
  231. .u-button--mini {
  232. height: 52rpx;
  233. }
  234. }
  235. .edit_area {
  236. padding: 32rpx;
  237. background-color: #fff;
  238. margin-top: 24rpx;
  239. .u-textarea {
  240. padding: 0;
  241. }
  242. }
  243. .settings_row {
  244. margin-top: 24rpx;
  245. .choose_row {
  246. @include nomalEllipsis;
  247. max-width: 300rpx;
  248. }
  249. }
  250. }
  251. </style>