uploadlink.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view :style="{marginTop:navH}"></view>
  6. <view @click="toRecord()">
  7. <view style="display: flex;justify-content: center;">
  8. <image style="height: 60rpx;width: 60rpx;" src="../../static/img/icon-clock.png"></image>
  9. </view>
  10. <view style="display: flex;justify-content: center;">
  11. <p style="font-size: 30rpx;">查看修改/反馈记录</p>
  12. </view>
  13. </view>
  14. <view v-if="!loading && !onlyShow">
  15. <!-- 多行输入框 -->
  16. <view style="margin: 40rpx;font-size: 32rpx">
  17. <p style="margin-bottom: 20rpx;">上传链接</p>
  18. <textarea v-model="link_url" style="height: 50px;width: 100%;"
  19. placeholder="请删除中文等其他字符,仅输入https://或http://开头的发布链接,样叽会对此进行质检~" />
  20. </view>
  21. <view style="margin: 0 40rpx;">
  22. <p style="margin-bottom: 20rpx;">上传作品收录/发布截图</p>
  23. <htz-image-upload :max="1" mediaType="image" name="file" :chooseNum="1" v-model="imageData"
  24. @chooseSuccess="ceshiChooseSuccess1">
  25. </htz-image-upload>
  26. </view>
  27. <view class="signup">
  28. <button type="default" class="but1" :loading="loading" @click="submit()">
  29. 提交链接</button>
  30. </view>
  31. </view>
  32. <view v-if="!loading && onlyShow">
  33. <view style="margin: 20rpx;">
  34. <!-- 图片 -->
  35. <p>{{link_url}}</p>
  36. <view style="display: flex;">
  37. <image :src="imageData" mode="aspectFit"></image>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import mvBar from "@/components/mys_navBar/mysNavBar";
  45. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  46. import getPolicyEncode from '@/components/obs/getPolicy.js';
  47. import getSignature from '@/components/obs/GetSignature.js';
  48. export default {
  49. components: {
  50. mvBar,
  51. htzImageUpload,
  52. },
  53. data() {
  54. return {
  55. onlyShow: false,
  56. loading: true,
  57. navH: getApp().globalData.navHeight,
  58. taskId: "",
  59. link_url: "",
  60. imageData: [],
  61. linkStatus: "",
  62. mysNavConfig: {
  63. /* 开启单页显示首页图标 */
  64. isHome: true,
  65. /* 固定导航 */
  66. navFixed: true,
  67. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  68. navTitle: {
  69. text: "上传链接",
  70. color: "",
  71. fontSize: "32rpx", // px upx rpx
  72. fontWeight: "normal", // 100 - 700
  73. },
  74. btnType: "type2",
  75. onLeftClick: '',
  76. /* type2 按钮 */
  77. type2Config: {
  78. // 左图标
  79. leftPath: "/static/img/png2.png",
  80. // 右图标
  81. rightPath: "/static/img/png4.png",
  82. // 圆角
  83. radius: "40rpx",
  84. },
  85. },
  86. }
  87. },
  88. onLoad(options) {
  89. let data = options.textObj.replace(/""/g, "");
  90. data = JSON.parse(decodeURIComponent(data))
  91. this.taskId = data.taskId
  92. this.linkStatus = data.linkStatus
  93. this.getLink()
  94. },
  95. methods: {
  96. async getLink() {
  97. this.loading = true
  98. uni.showLoading({
  99. title: '加载中'
  100. });
  101. await this.$https.get('/youngee/c/t/g/get-unsubmit-task-link' +
  102. "?" +
  103. "task_id" +
  104. "=" +
  105. this.taskId)
  106. .then(res => {
  107. console.log(res)
  108. if (res.data.data != null) {
  109. this.onlyShow = true
  110. this.imageData.push(res.data.data.photo_url)
  111. this.link_url = res.data.data.link_url
  112. }
  113. })
  114. uni.hideLoading();
  115. this.loading = false
  116. },
  117. toRecord() {
  118. var data = {
  119. taskId: this.taskId,
  120. };
  121. data = JSON.stringify(data)
  122. uni.navigateTo({
  123. url: '/pages/workspace/linkrecord?textObj=' + encodeURIComponent(data)
  124. });
  125. },
  126. submit() {
  127. // 校验
  128. if (this.link_url == "" || (this.link_url.substring(0, 8) != "https://" && this.link_url.substring(0, 7) !=
  129. "http://")) {
  130. uni.showToast({
  131. title: '请输入正确的发布链接',
  132. icon: 'none'
  133. })
  134. return
  135. }
  136. if (this.imageData.length == 0) {
  137. uni.showToast({
  138. title: '请上传收录/发布截图',
  139. icon: 'none'
  140. })
  141. return
  142. }
  143. let that = this
  144. uni.showModal({
  145. title: '提示',
  146. content: '提交后无法修改并进行审核,确认提交?',
  147. success: async function(res) {
  148. if (res.confirm) {
  149. // 调用添加链接接口
  150. await that.$https.post('/youngee/c/t/p/add-task-link', {
  151. task_id: that.taskId,
  152. link_url: that.link_url,
  153. photo_url: that.imageData[0],
  154. })
  155. .then(res => {
  156. console.log(res)
  157. })
  158. await that.$https.get('/youngee/c/t/g/submit-task-link' +
  159. "?" +
  160. "task_id" +
  161. "=" +
  162. that.taskId)
  163. .then(res => {
  164. console.log(res)
  165. })
  166. uni.navigateBack()
  167. } else if (res.cancel) {
  168. console.log('用户点击取消');
  169. }
  170. }
  171. });
  172. },
  173. ceshiChooseSuccess1(tempFilePaths, e) { //选择图片返回
  174. console.log('ceshiChooseSuccess', tempFilePaths, e);
  175. if (e == 0) {
  176. this.store = 'talent_upload/' + this.guid() + '.png'
  177. } else if (e == 1) {
  178. this.store = 'talent_upload/' + this.guid() + '.mp4'
  179. }
  180. /****************
  181. 以下代码是自定义上传逻辑,仅供参考
  182. ***************/
  183. this.imgUpload1(tempFilePaths);
  184. /*******************************/
  185. console.log("imgdata" + this.imageData)
  186. },
  187. imgUpload1(tempFilePaths) {
  188. let that = this
  189. console.log('imgUpload', tempFilePaths)
  190. let config = {
  191. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  192. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  193. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  194. };
  195. let fileName = this.store; //指定上传到OBS桶中的对象名
  196. // let fileName = "talent_upload/icon-arrow-right.png"
  197. let OBSPolicy = { //设定policy内容
  198. "expiration": "2089-12-31T12:00:00.000Z",
  199. "conditions": [{
  200. "bucket": "horastar"
  201. }, //Bucket name
  202. // {"bucket": "goin"},
  203. {
  204. 'key': fileName
  205. }
  206. ]
  207. }
  208. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  209. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  210. uni.uploadFile({
  211. //url: config.EndPoint,
  212. url: config.EndPoint,
  213. filePath: tempFilePaths[0],
  214. name: 'file',
  215. formData: {
  216. 'AccessKeyID': config.AccessKeyId,
  217. 'policy': policyEncoded,
  218. 'signature': signature,
  219. 'key': fileName,
  220. },
  221. success: function(res) {
  222. console.log(res.statusCode); //打印响应状态码
  223. if (res.statusCode == '204') {
  224. that.imageData.push(config.EndPoint + '/' + fileName);
  225. console.log('上传图片成功', res)
  226. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  227. console.log(obs_url)
  228. // that.formData.home_img = obs_url
  229. uni.showToast({
  230. title: '上传成功',
  231. icon: '成功'
  232. });
  233. } else {
  234. console.log('上传图片失败', res)
  235. uni.showToast({
  236. title: '上传失败',
  237. icon: '失败'
  238. });
  239. }
  240. },
  241. fail: function(e) {
  242. console.log(e);
  243. uni.showToast({
  244. title: '上传失败22222',
  245. icon: '失败'
  246. });
  247. }
  248. })
  249. },
  250. guid() {
  251. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  252. var r = Math.random() * 16 | 0,
  253. v = c == 'x' ? r : (r & 0x3 | 0x8);
  254. return v.toString(16);
  255. });
  256. },
  257. }
  258. }
  259. </script>
  260. <style lang="scss" scoped>
  261. .signup {
  262. box-shadow: 0rpx 5rpx 40rpx #ccc;
  263. width: 100%;
  264. position: fixed;
  265. bottom: 0rpx;
  266. display: flex;
  267. height: 90rpx;
  268. padding-top: 2%;
  269. background-color: #FFFFFF;
  270. }
  271. .but1 {
  272. width: 60%;
  273. background-color: #f2d22d;
  274. border-radius: 20rpx;
  275. font-size: 36rpx;
  276. line-height: 200%;
  277. letter-spacing: 10rpx;
  278. font-weight: 500;
  279. height: 80%;
  280. &.on {
  281. background-color: #C0C0C0;
  282. }
  283. }
  284. </style>